package com.tencent.mm.at;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.a.e;
import com.tencent.mm.ai.b;
import com.tencent.mm.ai.f;
import com.tencent.mm.ai.g;
import com.tencent.mm.ai.m;
import com.tencent.mm.al.c;
import com.tencent.mm.i.d;
import com.tencent.mm.i.g.a;
import com.tencent.mm.model.bf;
import com.tencent.mm.model.bh;
import com.tencent.mm.model.r;
import com.tencent.mm.model.t;
import com.tencent.mm.modelstat.h;
import com.tencent.mm.network.k;
import com.tencent.mm.network.q;
import com.tencent.mm.platformtools.ae;
import com.tencent.mm.plugin.messenger.foundation.a.j;
import com.tencent.mm.pointers.PInt;
import com.tencent.mm.pointers.PString;
import com.tencent.mm.protocal.protobuf.SKBuiltinBuffer_t;
import com.tencent.mm.protocal.protobuf.bts;
import com.tencent.mm.protocal.protobuf.clk;
import com.tencent.mm.protocal.protobuf.cll;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import com.tencent.mm.sdk.platformtools.al;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.sdk.platformtools.br;
import com.tencent.mm.storage.bi;
import com.tencent.ttpic.baseutils.FileUtils;
import com.tencent.ytcommon.BuildConfig;
import java.util.Map;
import junit.framework.Assert;

public final class l extends m implements k {
    public static boolean DEBUG = true;
    private static long fFD;
    private String TAG;
    private float cEB;
    public String cMr;
    public bi csG;
    private long eFm;
    private int eFn;
    private e eFo;
    private boolean eFu;
    private final b ehh;
    private f ehi;
    private int fDC;
    private long fDH;
    private final g fEW;
    public long fEX;
    private h fEZ;
    private String fFA;
    private String fFB;
    public String fFC;
    private String fFa;
    private int fFb;
    private int fFe;
    private a fFk;
    private String fFq;
    private String fFr;
    private boolean fFs;
    private e fFt;
    private int fFu;
    b fFv;
    private String fFw;
    public String fFx;
    public boolean fFy;
    private float fFz;
    private int scene;
    private int startOffset;
    private long startTime;

    static /* synthetic */ e d(l lVar) {
        AppMethodBeat.i(78348);
        e agY = lVar.agY();
        AppMethodBeat.o(78348);
        return agY;
    }

    static /* synthetic */ e e(l lVar) {
        AppMethodBeat.i(78349);
        e agZ = lVar.agZ();
        AppMethodBeat.o(78349);
        return agZ;
    }

    private e agY() {
        AppMethodBeat.i(78331);
        if (this.eFo == null) {
            this.eFo = o.ahl().b(Long.valueOf(this.eFm));
        }
        e eVar = this.eFo;
        AppMethodBeat.o(78331);
        return eVar;
    }

    private e agZ() {
        AppMethodBeat.i(78332);
        if (this.fFt == null) {
            this.fFt = o.ahl().b(Long.valueOf(this.fEX));
        }
        e eVar = this.fFt;
        AppMethodBeat.o(78332);
        return eVar;
    }

    public l(String str, String str2, String str3, int i) {
        this(str, str2, str3, i, BuildConfig.FLAVOR, BuildConfig.FLAVOR);
    }

    public l(String str, String str2, String str3, int i, g gVar, int i2, a aVar) {
        this(3, str, str2, str3, i, gVar, i2, BuildConfig.FLAVOR, BuildConfig.FLAVOR, true, 2130838182);
        AppMethodBeat.i(78333);
        this.fFv = new b(this, aVar);
        AppMethodBeat.o(78333);
    }

    private l(String str, String str2, String str3, int i, String str4, String str5) {
        this(4, str, str2, str3, i, null, 0, str4, str5, false, -1);
    }

    public l(int i, String str, String str2, String str3, int i2, g gVar, int i3, String str4, String str5, boolean z, int i4) {
        this(i, str, str2, str3, i2, gVar, i3, str4, str5, z, i4, 0, -1000.0f, -1000.0f, -1);
    }

    public l(int i, String str, String str2, String str3, int i2, g gVar, int i3, String str4, String str5, boolean z, int i4, int i5, float f, float f2, long j) {
        AppMethodBeat.i(78334);
        this.TAG = "MicroMsg.NetSceneUploadMsgImg";
        this.fFq = BuildConfig.FLAVOR;
        this.fFr = BuildConfig.FLAVOR;
        this.fFs = true;
        this.fFu = 16384;
        this.fDC = 0;
        this.csG = null;
        this.fEZ = null;
        this.fFa = BuildConfig.FLAVOR;
        this.startTime = 0;
        this.startOffset = -1;
        this.fFb = 0;
        this.fFv = new b(this, null);
        this.fFk = new 4(this);
        this.eFu = false;
        ab.i(this.TAG, "dkupimg init uploadsrc:%d from:%s to:%s ori:%s cmptype:%d prog:%s rotate:%d cdn:%s thumb:%s chatt:%b , res:%d run:%b [%s], scene: %d, longtitude: %f, latitude: %f", new Object[]{Integer.valueOf(i), str, str2, str3, Integer.valueOf(i2), gVar, Integer.valueOf(i3), str4, str5, Boolean.valueOf(z), Integer.valueOf(i4), Boolean.TRUE, bo.dpG(), Integer.valueOf(i5), Float.valueOf(f), Float.valueOf(f2)});
        this.fFy = z;
        this.fFe = i4;
        this.fEW = gVar;
        this.fDC = i2;
        this.scene = i5;
        this.cEB = f2;
        this.fFz = f;
        this.eFn = i;
        this.fFC = str3;
        PString pString = new PString();
        PInt pInt = new PInt();
        PInt pInt2 = new PInt();
        this.fFw = str4;
        pString.value = str5;
        String str6 = null;
        if (j > 0) {
            str6 = o.ahl().q(o.ahl().b(Long.valueOf(j)).fDE, BuildConfig.FLAVOR, BuildConfig.FLAVOR);
        }
        this.fEX = o.ahl().a(str3, str6, i2, i, i3, pString, pInt, pInt2, BuildConfig.FLAVOR, BuildConfig.FLAVOR, -1, null, null, null);
        this.eFm = this.fEX;
        ab.i(this.TAG, "FROM A UI :" + str2 + " " + this.fEX);
        if (this.fEX < 0 || !i.lA((int) this.fEX)) {
            ab.e(this.TAG, "insert to img storage failed id:" + this.fEX);
            this.fDH = -1;
            this.ehh = null;
            AppMethodBeat.o(78334);
            return;
        }
        e agY;
        int i6;
        Assert.assertTrue(this.fEX >= 0);
        b.a aVar = new b.a();
        aVar.fsJ = new clk();
        aVar.fsK = new cll();
        aVar.uri = "/cgi-bin/micromsg-bin/uploadmsgimg";
        aVar.fsI = 110;
        aVar.fsL = 9;
        aVar.fsM = 1000000009;
        this.ehh = aVar.acD();
        this.cMr = str2;
        this.csG = new bi();
        this.csG.setType(t.nL(str2));
        this.csG.ju(str2);
        this.csG.hO(1);
        this.csG.setStatus(1);
        this.csG.jv(pString.value);
        this.csG.hZ(pInt.value);
        this.csG.ia(pInt2.value);
        this.csG.eJ(bf.oC(this.csG.field_talker));
        this.csG.setContent(str4);
        com.tencent.mm.l.a.a.KG().g(this.csG);
        this.fDH = ((j) com.tencent.mm.kernel.g.K(j.class)).bOr().Z(this.csG);
        Assert.assertTrue(this.fDH >= 0);
        ab.i(this.TAG, "NetSceneUploadMsgImg: local msgId = " + this.fDH);
        e agZ = agZ();
        agZ.fG((long) ((int) this.fDH));
        o.ahl().a(Long.valueOf(this.fEX), agZ);
        if (i2 == 1) {
            this.eFm = (long) agZ.fDJ;
            agY = agY();
        } else {
            agY = agZ;
        }
        agY.lt(e.cs(o.ahl().q(agY.fDz, BuildConfig.FLAVOR, BuildConfig.FLAVOR)));
        o.ahl().a(Long.valueOf(this.eFm), agY);
        ab.i(this.TAG, "NetSceneUploadMsgImg: local imgId = " + this.eFm + " img len = " + agY.frO);
        clk clk = (clk) this.ehh.fsG.fsP;
        clk.vEB = new bts().alV(str);
        clk.vEC = new bts().alV(str2);
        clk.ptx = agY.offset;
        clk.ptw = agY.frO;
        clk.nao = this.csG.getType();
        clk.wqw = i2;
        if (com.tencent.mm.network.ab.ch(ah.getContext())) {
            i6 = 1;
        } else {
            i6 = 2;
        }
        clk.vZF = i6;
        clk.xbN = agY.cvd;
        clk.vRz = agY.fDD;
        clk.xjh = pInt2.value;
        clk.xji = pInt.value;
        a sg = f.sg(str4);
        if (!(sg == null || bo.isNullOrNil(sg.appId))) {
            clk.fKh = sg.appId;
            clk.vCs = sg.mediaTagName;
            clk.vCu = sg.messageAction;
            clk.vCt = sg.messageExt;
        }
        ab.i(this.TAG, "LINE237 thumb.width:%d,thumb.height:%d", new Object[]{Integer.valueOf(clk.xjh), Integer.valueOf(clk.xji)});
        if (clk.vRz == 0) {
            clk.vRz = i == 4 ? 2 : 1;
        }
        ab.d(this.TAG, "dkimgsource: %d, forwardtype:%d", new Object[]{Integer.valueOf(agY.cvd), Integer.valueOf(clk.vRz)});
        if (agY.offset == 0) {
            this.fEZ = new h(110, true, (long) agY.frO);
        }
        long currentTimeMillis = System.currentTimeMillis();
        lD(i2);
        ab.d(this.TAG, "hy: create HDThumb using %d ms", new Object[]{Long.valueOf(System.currentTimeMillis() - currentTimeMillis)});
        if (gVar != null) {
            al.d(new 2(this, gVar, agY.offset, agY.frO));
        }
        AppMethodBeat.o(78334);
    }

    public l(long j, String str, String str2, String str3, int i, g gVar, int i2, String str4, String str5) {
        e agY;
        String str6;
        AppMethodBeat.i(78335);
        this.TAG = "MicroMsg.NetSceneUploadMsgImg";
        this.fFq = BuildConfig.FLAVOR;
        this.fFr = BuildConfig.FLAVOR;
        this.fFs = true;
        this.fFu = 16384;
        this.fDC = 0;
        this.csG = null;
        this.fEZ = null;
        this.fFa = BuildConfig.FLAVOR;
        this.startTime = 0;
        this.startOffset = -1;
        this.fFb = 0;
        this.fFv = new b(this, null);
        this.fFk = new 4(this);
        this.eFu = false;
        ab.i(this.TAG, "dkupimg init id:%d uploadsrc:%d from:%s to:%s ori:%s cmptype:%d prog:%s rotate:%d cdn:%s thumb:%s chatt:%b , res:%d run:%b [%s]", new Object[]{Long.valueOf(j), Integer.valueOf(3), str, str2, str3, Integer.valueOf(i), gVar, Integer.valueOf(i2), str4, str5, Boolean.TRUE, Integer.valueOf(2130838182), Boolean.TRUE, bo.dpG()});
        this.fFy = true;
        this.fFe = 2130838182;
        this.fEW = gVar;
        this.fDC = i;
        this.eFn = 3;
        this.fFC = str3;
        PInt pInt = new PInt();
        PInt pInt2 = new PInt();
        this.fFw = str4;
        this.fEX = j;
        this.eFm = this.fEX;
        e agZ = agZ();
        this.csG = ((j) com.tencent.mm.kernel.g.K(j.class)).bOr().jf(agZ.fDH);
        this.fDH = this.csG.field_msgId;
        pInt2.value = this.csG.dJx;
        pInt.value = this.csG.dJw;
        if (i == 1) {
            this.eFm = (long) agZ.fDJ;
            this.eFo = null;
            agY = agY();
        } else {
            agY = agZ;
        }
        if (this.csG.field_talker == null || this.csG.field_talker.equals(str2)) {
            str6 = str2;
        } else {
            ab.e(this.TAG, "fatal!! Send user mis-match, want:%s, fact:%s", new Object[]{str2, this.csG.field_talker});
            com.tencent.mm.plugin.report.service.h.pYm.a(594, 4, 1, true);
            str6 = this.csG.field_talker;
        }
        ab.i(this.TAG, "NetSceneUploadMsgImg: local msgId = " + this.csG.field_msgId);
        ab.d(this.TAG, "FROM A UI :" + str2 + "   msg:" + str6 + this.fEX);
        if (this.fEX < 0 || !i.lA((int) this.fEX)) {
            ab.e(this.TAG, "insert to img storage failed id:" + this.fEX);
            this.fDH = -1;
            this.ehh = null;
            AppMethodBeat.o(78335);
            return;
        }
        int i3;
        Assert.assertTrue(this.fEX >= 0);
        b.a aVar = new b.a();
        aVar.fsJ = new clk();
        aVar.fsK = new cll();
        aVar.uri = "/cgi-bin/micromsg-bin/uploadmsgimg";
        aVar.fsI = 110;
        aVar.fsL = 9;
        aVar.fsM = 1000000009;
        this.ehh = aVar.acD();
        ab.i(this.TAG, "NetSceneUploadMsgImg: local imgId = " + this.eFm + " img len = " + agY.frO);
        clk clk = (clk) this.ehh.fsG.fsP;
        clk.vEB = new bts().alV(str);
        clk.vEC = new bts().alV(str6);
        clk.ptx = agY.offset;
        clk.ptw = agY.frO;
        clk.nao = this.csG.getType();
        clk.wqw = i;
        if (com.tencent.mm.network.ab.ch(ah.getContext())) {
            i3 = 1;
        } else {
            i3 = 2;
        }
        clk.vZF = i3;
        clk.xbN = agY.cvd;
        clk.vRz = agY.fDD;
        clk.xjh = pInt2.value;
        clk.xji = pInt.value;
        ab.i(this.TAG, "LINE350 thumb.width:%d,thumb.height:%d", new Object[]{Integer.valueOf(clk.xjh), Integer.valueOf(clk.xji)});
        if (clk.vRz == 0) {
            clk.vRz = 1;
        }
        ab.d(this.TAG, "dkimgsource: %d, forwardtype:%d", new Object[]{Integer.valueOf(agY.cvd), Integer.valueOf(clk.vRz)});
        if (agY.offset == 0) {
            this.fEZ = new h(110, true, (long) agY.frO);
        }
        al.d(new 3(this, gVar, agY.offset, agY.frO));
        AppMethodBeat.o(78335);
    }

    public final void lD(int i) {
        int i2 = 1;
        AppMethodBeat.i(78336);
        if (this.csG == null) {
            ab.w(this.TAG, "createHDThumb but msg is null msgLocalId[%d], compressType[%d]", new Object[]{Long.valueOf(this.fDH), Integer.valueOf(i)});
            AppMethodBeat.o(78336);
            return;
        }
        if (!this.fFy) {
            o.ahl().a(this.csG.field_imgPath, com.tencent.mm.bz.a.getDensity(ah.getContext()), true);
        } else if (this.csG.dJA == 0) {
            boolean a = o.ahl().a(this.csG, this.fFe, i);
            bi biVar = this.csG;
            if (!a) {
                i2 = 0;
            }
            biVar.ic(i2);
            ((j) com.tencent.mm.kernel.g.K(j.class)).bOr().a(this.fDH, this.csG);
            AppMethodBeat.o(78336);
            return;
        }
        AppMethodBeat.o(78336);
    }

    public l(int i, int i2) {
        AppMethodBeat.i(78337);
        this.TAG = "MicroMsg.NetSceneUploadMsgImg";
        this.fFq = BuildConfig.FLAVOR;
        this.fFr = BuildConfig.FLAVOR;
        this.fFs = true;
        this.fFu = 16384;
        this.fDC = 0;
        this.csG = null;
        this.fEZ = null;
        this.fFa = BuildConfig.FLAVOR;
        this.startTime = 0;
        this.startOffset = -1;
        this.fFb = 0;
        this.fFv = new b(this, null);
        this.fFk = new 4(this);
        this.eFu = false;
        ab.i(this.TAG, "dkupimg init id:%d cmptype:%d  [%s]", new Object[]{Integer.valueOf(i), Integer.valueOf(i2), bo.dpG()});
        this.fEX = (long) i;
        this.eFm = (long) i;
        this.fDC = i2;
        b.a aVar = new b.a();
        aVar.fsJ = new clk();
        aVar.fsK = new cll();
        aVar.uri = "/cgi-bin/micromsg-bin/uploadmsgimg";
        aVar.fsI = 110;
        aVar.fsL = 9;
        aVar.fsM = 1000000009;
        this.ehh = aVar.acD();
        this.fEW = null;
        ab.d(this.TAG, "FROM B SERVICE:" + this.fEX);
        if (i.lA((int) this.fEX)) {
            e b;
            e b2 = o.ahl().b(Long.valueOf(this.fEX));
            this.fDH = b2.fDH;
            if (i2 == 1) {
                this.eFm = (long) b2.fDJ;
                b = o.ahl().b(Long.valueOf(this.eFm));
            } else {
                b = b2;
            }
            b2 = o.ahl().lz((int) b.fDy);
            if (b2 != null) {
                this.fDH = b2.fDH;
            }
            this.csG = ((j) com.tencent.mm.kernel.g.K(j.class)).bOr().jf(this.fDH);
            if (this.csG == null || this.csG.field_msgId == this.fDH) {
                if (this.csG != null) {
                    int i3;
                    clk clk = (clk) this.ehh.fsG.fsP;
                    clk.vEB = new bts().alV(r.Yz());
                    clk.vEC = new bts().alV(this.csG.field_talker);
                    clk.ptx = b.offset;
                    clk.ptw = b.frO;
                    clk.nao = this.csG.getType();
                    clk.wqw = i2;
                    if (com.tencent.mm.network.ab.ch(ah.getContext())) {
                        i3 = 1;
                    } else {
                        i3 = 2;
                    }
                    clk.vZF = i3;
                    clk.xbN = b.cvd;
                    clk.vRz = b.fDD;
                    clk.vRz = b.fDD;
                    clk.xjh = this.csG.dJx;
                    clk.xji = this.csG.dJw;
                    a sg = f.sg(this.csG.field_content);
                    if (!(sg == null || bo.isNullOrNil(sg.appId))) {
                        this.eFn = b.cvd;
                        clk.fKh = sg.appId;
                        clk.vCs = sg.mediaTagName;
                        clk.vCu = sg.messageAction;
                        clk.vCt = sg.messageExt;
                        this.fFw = this.csG.field_content;
                    }
                    ab.i(this.TAG, "LINE425 thumb.width:%d,thumb.height:%d", new Object[]{Integer.valueOf(clk.xjh), Integer.valueOf(clk.xji)});
                    ab.d(this.TAG, "dkimgsource: %d, forwardtype:%d", new Object[]{Integer.valueOf(b.cvd), Integer.valueOf(clk.vRz)});
                    if (b.offset == 0) {
                        this.fEZ = new h(110, true, (long) b.frO);
                    }
                }
                AppMethodBeat.o(78337);
                return;
            }
            ab.w(this.TAG, "init get msg by id failed:%d", new Object[]{Long.valueOf(this.fDH)});
            com.tencent.mm.plugin.report.service.h.pYm.a(111, 206, 1, false);
            this.csG = null;
            AppMethodBeat.o(78337);
            return;
        }
        this.fEX = -1;
        AppMethodBeat.o(78337);
    }

    public l(int i, int i2, byte b) {
        AppMethodBeat.i(78338);
        this.TAG = "MicroMsg.NetSceneUploadMsgImg";
        this.fFq = BuildConfig.FLAVOR;
        this.fFr = BuildConfig.FLAVOR;
        this.fFs = true;
        this.fFu = 16384;
        this.fDC = 0;
        this.csG = null;
        this.fEZ = null;
        this.fFa = BuildConfig.FLAVOR;
        this.startTime = 0;
        this.startOffset = -1;
        this.fFb = 0;
        this.fFv = new b(this, null);
        this.fFk = new 4(this);
        this.eFu = false;
        ab.i(this.TAG, "dkupimg init id:%d cmptype:%d pro:%s  [%s]", new Object[]{Integer.valueOf(i), Integer.valueOf(i2), null, bo.dpG()});
        this.fEX = (long) i;
        this.eFm = (long) i;
        this.fDC = i2;
        b.a aVar = new b.a();
        aVar.fsJ = new clk();
        aVar.fsK = new cll();
        aVar.uri = "/cgi-bin/micromsg-bin/uploadmsgimg";
        aVar.fsI = 110;
        aVar.fsL = 9;
        aVar.fsM = 1000000009;
        this.ehh = aVar.acD();
        this.fEW = null;
        ab.d(this.TAG, "FROM C SERVICE:" + this.fEX);
        if (i.lA((int) this.fEX)) {
            e b2;
            e b3 = o.ahl().b(Long.valueOf(this.fEX));
            this.fDH = b3.fDH;
            b3.setStatus(0);
            b3.eI(0);
            b3.setOffset(0);
            o.ahl().a((int) this.eFm, b3);
            if (i2 == 1) {
                this.eFm = (long) b3.fDJ;
                b2 = o.ahl().b(Long.valueOf(this.eFm));
            } else {
                b2 = b3;
            }
            this.csG = ((j) com.tencent.mm.kernel.g.K(j.class)).bOr().jf(this.fDH);
            if (this.csG != null) {
                int i3;
                this.csG.setStatus(1);
                String str = b2.fDB;
                if (str == null || !str.startsWith("THUMBNAIL_DIRPATH://")) {
                    this.csG.jv("THUMBNAIL://" + b2.fDy);
                } else {
                    this.csG.jv(str);
                }
                ((j) com.tencent.mm.kernel.g.K(j.class)).bOr().a(this.fDH, this.csG);
                clk clk = (clk) this.ehh.fsG.fsP;
                clk.vEB = new bts().alV(r.Yz());
                clk.vEC = new bts().alV(this.csG.field_talker);
                clk.ptx = b2.offset;
                clk.ptw = b2.frO;
                clk.nao = this.csG.getType();
                clk.wqw = i2;
                if (com.tencent.mm.network.ab.ch(ah.getContext())) {
                    i3 = 1;
                } else {
                    i3 = 2;
                }
                clk.vZF = i3;
                clk.xbN = b2.cvd;
                clk.vRz = b2.fDD;
                clk.xjh = this.csG.dJx;
                clk.xji = this.csG.dJw;
                ab.i(this.TAG, "LINE492 thumb.width:%d,thumb.height:%d", new Object[]{Integer.valueOf(clk.xjh), Integer.valueOf(clk.xji)});
                ab.d(this.TAG, "dkimgsource: %d, forwardtype:%d", new Object[]{Integer.valueOf(b2.cvd), Integer.valueOf(clk.vRz)});
                if (b2.offset == 0) {
                    this.fEZ = new h(110, true, (long) b2.frO);
                }
            }
            AppMethodBeat.o(78338);
            return;
        }
        this.fEX = -1;
        AppMethodBeat.o(78338);
    }

    public final m.b b(q qVar) {
        return m.b.ftu;
    }

    private boolean a(e eVar, int i) {
        AppMethodBeat.i(78339);
        if (t.nJ(this.csG.field_talker)) {
            ab.w(this.TAG, "cdntra not use cdn user:%s", new Object[]{this.csG.field_talker});
            AppMethodBeat.o(78339);
            return false;
        }
        com.tencent.mm.al.f.afx();
        if (!com.tencent.mm.al.b.lg(1) && bo.isNullOrNil(eVar.fDK)) {
            r2 = new Object[2];
            com.tencent.mm.al.f.afx();
            r2[0] = Boolean.valueOf(com.tencent.mm.al.b.lg(1));
            r2[1] = eVar.fDK;
            ab.w(this.TAG, "cdntra not use cdn flag:%b getCdnInfo:%s", r2);
            AppMethodBeat.o(78339);
            return false;
        } else if (bo.isNullOrNil(this.fFa)) {
            ab.w(this.TAG, "cdntra genClientId failed not use cdn imgLocalId:%d", new Object[]{Long.valueOf(this.eFm)});
            AppMethodBeat.o(78339);
            return false;
        } else {
            String q = o.ahl().q(eVar.fDz, BuildConfig.FLAVOR, BuildConfig.FLAVOR);
            String q2 = o.ahl().q(eVar.fDA, BuildConfig.FLAVOR, BuildConfig.FLAVOR);
            String q3 = o.ahl().q(eVar.fDB, BuildConfig.FLAVOR, BuildConfig.FLAVOR);
            String q4 = o.ahl().q(eVar.fDE, BuildConfig.FLAVOR, BuildConfig.FLAVOR);
            com.tencent.mm.i.g gVar = new com.tencent.mm.i.g();
            gVar.egl = this.fFk;
            gVar.field_mediaId = this.fFa;
            gVar.field_fileType = this.fFb;
            gVar.field_talker = this.csG.field_talker;
            gVar.field_chattype = t.kH(this.csG.field_talker) ? 1 : 0;
            gVar.field_priority = com.tencent.mm.i.a.efC;
            gVar.field_needStorage = false;
            gVar.field_isStreamMedia = false;
            gVar.field_sendmsg_viacdn = true;
            gVar.field_enable_hitcheck = this.fFs;
            gVar.field_force_aeskeycdn = false;
            gVar.field_trysafecdn = true;
            if (i == -5103237) {
                this.fFa = c.a("upimgjpg", this.csG.field_createTime, this.csG.field_talker, this.csG.field_msgId + "_" + this.eFm + "_" + this.fDC);
                gVar.field_fullpath = q;
                gVar.field_thumbpath = q3;
                gVar.field_midimgpath = q2;
                gVar.lastError = i;
                gVar.field_mediaId = this.fFa;
            } else {
                boolean z;
                boolean biZ = ((com.tencent.mm.plugin.emoji.b.c) com.tencent.mm.kernel.g.K(com.tencent.mm.plugin.emoji.b.c.class)).biZ();
                if (this.eFn == 4 && com.tencent.mm.vfs.e.ct(q4)) {
                    z = biZ;
                } else {
                    q4 = ((com.tencent.mm.plugin.emoji.b.c) com.tencent.mm.kernel.g.K(com.tencent.mm.plugin.emoji.b.c.class)).IP(q);
                    z = this.fDC == 0 && !com.tencent.mm.sdk.platformtools.r.amq(q).equals(FileUtils.PIC_POSTFIX_PNG) && aL(q, q4);
                    if (z) {
                        eVar.sf(((com.tencent.mm.plugin.emoji.b.c) com.tencent.mm.kernel.g.K(com.tencent.mm.plugin.emoji.b.c.class)).IP(eVar.fDz));
                    }
                }
                String IP = ((com.tencent.mm.plugin.emoji.b.c) com.tencent.mm.kernel.g.K(com.tencent.mm.plugin.emoji.b.c.class)).IP(q2);
                boolean aL = aL(q2, IP);
                if (!z) {
                    q4 = q;
                }
                gVar.field_fullpath = q4;
                gVar.field_thumbpath = q3;
                if (!aL) {
                    IP = q2;
                }
                gVar.field_midimgpath = IP;
                q4 = this.TAG;
                q = "hevc upload full size %b, use hevc %b, %b";
                Object[] objArr = new Object[3];
                if (gVar.field_fileType == com.tencent.mm.i.a.MediaType_FULLSIZEIMAGE) {
                    biZ = true;
                } else {
                    biZ = false;
                }
                objArr[0] = Boolean.valueOf(biZ);
                objArr[1] = Boolean.valueOf(z);
                objArr[2] = Boolean.valueOf(aL);
                ab.d(q4, q, objArr);
            }
            if (gVar.field_fileType == com.tencent.mm.i.a.MediaType_FULLSIZEIMAGE && bo.isNullOrNil(gVar.field_midimgpath)) {
                com.tencent.mm.al.f.afx();
                if (com.tencent.mm.al.b.lg(256)) {
                    ab.w(this.TAG, "summersafecdn send fullsizeimage but midimgpath is null set field_force_aeskeycdn true");
                    gVar.field_force_aeskeycdn = true;
                    gVar.field_trysafecdn = false;
                }
            }
            Map z2 = br.z(this.fFw, "msg");
            if (z2 != null) {
                if (this.fDC != 1) {
                    gVar.field_fileId = (String) z2.get(".msg.img.$cdnmidimgurl");
                    gVar.field_midFileLength = bo.getInt((String) z2.get(".msg.img.$length"), 0);
                    gVar.field_totalLen = 0;
                } else {
                    gVar.field_fileId = (String) z2.get(".msg.img.$cdnbigimgurl");
                    gVar.field_midFileLength = bo.getInt((String) z2.get(".msg.img.$length"), 0);
                    gVar.field_totalLen = 0;
                }
                gVar.field_aesKey = (String) z2.get(".msg.img.$aeskey");
            } else {
                ab.i(this.TAG, "parse cdnInfo failed. [%s]", new Object[]{eVar.fDK});
            }
            if (bo.isNullOrNil(gVar.field_aesKey)) {
                com.tencent.mm.al.f.afy();
                gVar.field_aesKey = com.tencent.mm.al.a.afp();
                ab.i(this.TAG, "summersafecdn cdntra oldAeskey is null and gen new[%s]", new Object[]{gVar.field_aesKey});
            }
            ab.i(this.TAG, "dkupimg src:%d fileid:%s", new Object[]{Integer.valueOf(eVar.cvd), gVar.field_fileId});
            this.fFq = gVar.field_fileId;
            this.fFr = gVar.field_aesKey;
            ab.d(this.TAG, "summersafecdn checkUseCdn field_enable_hitcheck[%b], field_fileType[%d], field_midimgpath[%s], field_fullpath[%s], aeskey[%s], fileid[%s], enable_hitcheck[%b], aeskeycdn[%b], trysafecdn[%b]", new Object[]{Boolean.valueOf(gVar.field_enable_hitcheck), Integer.valueOf(gVar.field_fileType), gVar.field_midimgpath, gVar.field_fullpath, gVar.field_aesKey, gVar.field_fileId, Boolean.valueOf(gVar.field_enable_hitcheck), Boolean.valueOf(gVar.field_force_aeskeycdn), Boolean.valueOf(gVar.field_trysafecdn)});
            this.fFB = null;
            if (com.tencent.mm.al.f.afx().e(gVar)) {
                if (bo.nullAsNil(eVar.fDK).length() <= 0) {
                    eVar.se("CDNINFO_SEND");
                    eVar.bJt = 4096;
                }
                AppMethodBeat.o(78339);
                return true;
            }
            com.tencent.mm.plugin.report.service.h.pYm.a(111, 205, 1, false);
            ab.e(this.TAG, "cdntra addSendTask failed. clientid:%s", new Object[]{this.fFa});
            this.fFa = BuildConfig.FLAVOR;
            AppMethodBeat.o(78339);
            return false;
        }
    }

    private boolean aL(String str, String str2) {
        AppMethodBeat.i(78340);
        if (((com.tencent.mm.plugin.emoji.b.c) com.tencent.mm.kernel.g.K(com.tencent.mm.plugin.emoji.b.c.class)).biZ()) {
            if (com.tencent.mm.vfs.e.asZ(str) > 0) {
                if (com.tencent.mm.vfs.e.asZ(str2) > 0) {
                    com.tencent.mm.plugin.report.service.h.pYm.k(944, 9, 1);
                    com.tencent.mm.vfs.e.deleteFile(str2);
                }
                if (!com.tencent.mm.vfs.e.ct(str2)) {
                    com.tencent.mm.vfs.e.atc(str2);
                }
                if (((com.tencent.mm.plugin.emoji.b.c) com.tencent.mm.kernel.g.K(com.tencent.mm.plugin.emoji.b.c.class)).dF(str, str2) == 0) {
                    AppMethodBeat.o(78340);
                    return true;
                }
                ab.w(this.TAG, "file to hevc failed %s", new Object[]{str});
            }
            AppMethodBeat.o(78340);
            return false;
        }
        AppMethodBeat.o(78340);
        return false;
    }

    public final int a(com.tencent.mm.network.e eVar, f fVar) {
        AppMethodBeat.i(78341);
        com.tencent.mm.kernel.g.RQ();
        com.tencent.mm.kernel.g.RS().m(new 5(this), 100);
        int lE;
        if (this.eFm < 0) {
            com.tencent.mm.plugin.report.service.h.pYm.a(111, 204, 1, false);
            ab.e(this.TAG, "doScene invalid imgLocalId:" + this.eFm);
            lE = lE(-1);
            AppMethodBeat.o(78341);
            return lE;
        } else if (this.csG == null) {
            com.tencent.mm.plugin.report.service.h.pYm.a(111, 203, 1, false);
            ab.e(this.TAG, "doScene msg is null imgid:%d", new Object[]{Long.valueOf(this.eFm)});
            i.lC((int) this.fEX);
            lE = lE(-2);
            AppMethodBeat.o(78341);
            return lE;
        } else {
            this.ehi = fVar;
            c(eVar);
            clk clk = (clk) this.ehh.fsG.fsP;
            e agY = agY();
            e lz = o.ahl().lz((int) agY.fDy);
            if (lz != null) {
                if (lz.status == -1) {
                    com.tencent.mm.plugin.report.service.h.pYm.a(111, 202, 1, false);
                    ab.e(this.TAG, "doScene hd img info is null or error.");
                    lE = lE(-3);
                    AppMethodBeat.o(78341);
                    return lE;
                }
            } else if (agY == null || agY.status == -1) {
                ab.e(this.TAG, "doScene img info is null or error.");
                lE = lE(-4);
                AppMethodBeat.o(78341);
                return lE;
            }
            if (com.tencent.mm.l.a.a.KG().kq(this.csG.field_talker)) {
                clk.vEG = com.tencent.mm.l.a.a.KG().h(this.csG);
            } else {
                String aae = bh.aae();
                if (!(aae == null || aae.equals(this.csG.dqJ)) || (aae == null && !bo.isNullOrNil(this.csG.dqJ))) {
                    this.csG.ix(aae);
                    ((j) com.tencent.mm.kernel.g.K(j.class)).bOr().a(this.csG.field_msgId, this.csG);
                }
                clk.vEG = this.csG.dqJ;
            }
            String q = o.ahl().q(agY.fDz, BuildConfig.FLAVOR, BuildConfig.FLAVOR);
            String q2 = o.ahl().q(agY.fDB, BuildConfig.FLAVOR, BuildConfig.FLAVOR);
            if (!bo.isNullOrNil(agY.fDA)) {
                o.ahl().q(agY.fDA, BuildConfig.FLAVOR, BuildConfig.FLAVOR);
            }
            if (e.cs(q) <= 0 || e.cs(q2) <= 0) {
                ab.e(this.TAG, "doScene invalid imgLocalId:%d filesize:[%d,%d] %s %s", new Object[]{Long.valueOf(this.eFm), Integer.valueOf(e.cs(q)), Integer.valueOf(e.cs(q2)), q, q2});
                lE = lE(-5);
                AppMethodBeat.o(78341);
                return lE;
            }
            if (clk.xja == null || bo.isNullOrNil(clk.xja.wVI)) {
                if (bo.isNullOrNil(this.fFa)) {
                    ab.i(this.TAG, "createMediaId time:%d talker:%s msg:%d img:%d compressType:%d", new Object[]{Long.valueOf(this.csG.field_createTime), this.csG.field_talker, Long.valueOf(this.csG.field_msgId), Long.valueOf(this.eFm), Integer.valueOf(this.fDC)});
                    this.fFa = c.a("upimg", this.csG.field_createTime, this.csG.field_talker, this.csG.field_msgId + "_" + this.eFm + "_" + this.fDC);
                }
                clk.xja = new bts().alV(this.fFa);
                bi biVar = this.csG;
                biVar.dJC = this.fFa;
                biVar.dqp = true;
            }
            if (this.startTime == 0) {
                this.startTime = bo.anU();
                this.startOffset = agY.offset;
                this.fFb = this.fDC == 1 ? com.tencent.mm.i.a.MediaType_FULLSIZEIMAGE : com.tencent.mm.i.a.MediaType_IMAGE;
            }
            ab.i(this.TAG, "before checkUseCdn %s, %s, imgBitPath:%s", new Object[]{q, q2, agY.fDz});
            if (a(agY, 0)) {
                ab.d(this.TAG, "cdntra use cdn return -1 for onGYNetEnd clientid:%s", new Object[]{clk.xja.wVI});
                AppMethodBeat.o(78341);
                return 0;
            }
            ab.i(this.TAG, "after checkUseCdn, it use cgi to upload image.");
            int i = agY.fDI;
            if (i >= acn()) {
                com.tencent.mm.plugin.report.service.h.pYm.a(111, 201, 1, false);
                ab.e(this.TAG, "doScene limit net time:".concat(String.valueOf(i)));
                i.lC((int) this.fEX);
                lE = lE(-6);
                AppMethodBeat.o(78341);
                return lE;
            }
            agY.lr(i + 1);
            agY.bJt = com.tencent.mm.plugin.appbrand.jsapi.container.b.CTRL_INDEX;
            o.ahl().a(Long.valueOf(this.eFm), agY);
            int i2 = agY.frO - agY.offset;
            if (i2 > this.fFu) {
                i2 = this.fFu;
            }
            e.cs(q);
            byte[] e = e.e(q, agY.offset, i2);
            if (e == null || e.length <= 0) {
                com.tencent.mm.plugin.report.service.h.pYm.a(111, 199, 1, false);
                ab.e(this.TAG, "doScene, file read buf error.");
                lE = lE(-8);
                AppMethodBeat.o(78341);
                return lE;
            }
            clk.pty = e.length;
            clk.ptx = agY.offset;
            clk.ptz = new SKBuiltinBuffer_t().setBuffer(e);
            if (this.fEZ != null) {
                this.fEZ.akj();
            }
            lE = a(eVar, this.ehh, this);
            if (lE < 0) {
                ab.e(this.TAG, "doScene netId error");
                i.lC((int) this.fEX);
                lE = lE(-9);
                AppMethodBeat.o(78341);
                return lE;
            }
            AppMethodBeat.o(78341);
            return lE;
        }
    }

    private int lE(int i) {
        AppMethodBeat.i(78342);
        ab.e(this.TAG, "do Scene error code : " + i + " hashcode : " + hashCode());
        if (this.fFv != null) {
            this.fFv.agX();
        }
        AppMethodBeat.o(78342);
        return -1;
    }

    public final int getType() {
        return 110;
    }

    public final int acn() {
        if (this.fDC == 0) {
            return 100;
        }
        return 1350;
    }

    public final void a(int i, int i2, int i3, String str, q qVar, byte[] bArr) {
        AppMethodBeat.i(78343);
        cll cll = (cll) ((b) qVar).fsH.fsP;
        ab.i(this.TAG, "cdntra onGYNetEnd errtype:" + i2 + " errcode:" + i3 + " useCdnTransClientId:" + this.fFa);
        if (i2 == 3 && i3 == -1 && !bo.isNullOrNil(this.fFa)) {
            ab.w(this.TAG, "cdntra using cdn trans,  wait cdn service callback! clientid:%s", new Object[]{this.fFa});
            AppMethodBeat.o(78343);
        } else if (i2 == 0 && i3 == 0) {
            this.fFu = cll.pty;
            if (this.fFu > 16384) {
                this.fFu = 16384;
            }
            e agY = agY();
            ab.v(this.TAG, "onGYNetEnd localId:" + this.eFm + "  totalLen:" + agY.frO + " offSet:" + agY.offset);
            if (cll.ptx < 0 || (cll.ptx > agY.frO && agY.frO > 0)) {
                com.tencent.mm.plugin.report.service.h.pYm.a(111, 197, 1, false);
                ab.e(this.TAG, "onGYNetEnd invalid server return value : startPos = " + cll.ptx + " img totalLen = " + agY.frO);
                i.lC((int) this.fEX);
                i.lB((int) this.fEX);
                com.tencent.mm.plugin.report.service.h.pYm.e(10420, new Object[]{Integer.valueOf(-2), Integer.valueOf(1), Long.valueOf(this.startTime), Long.valueOf(bo.anU()), Integer.valueOf(c.bW(ah.getContext())), Integer.valueOf(this.fFb), Integer.valueOf(0)});
                this.ehi.onSceneEnd(4, -2, BuildConfig.FLAVOR, this);
                if (this.fFv != null) {
                    this.fFv.agX();
                }
                AppMethodBeat.o(78343);
            } else if (cll.ptx < agY.offset || (f.b(agY) && this.fFu <= 0)) {
                ab.e(this.TAG, "onGYNetEnd invalid data startPos = " + cll.ptx + " totalLen = " + agY.frO + " off:" + agY.offset);
                i.lC((int) this.fEX);
                i.lB((int) this.fEX);
                this.ehi.onSceneEnd(4, -1, BuildConfig.FLAVOR, this);
                if (this.fFv != null) {
                    this.fFv.agX();
                }
                AppMethodBeat.o(78343);
            } else {
                ab.d("ImgInfoLogic", "resp.rImpl.getStartPos() " + cll.ptx);
                if (a(agY, cll.ptx, cll.ptF, cll.pcX, null) && a(this.ftf, this.ehi) < 0) {
                    i.lB((int) this.fEX);
                    this.ehi.onSceneEnd(3, -1, BuildConfig.FLAVOR, this);
                    if (this.fFv != null) {
                        this.fFv.agX();
                    }
                }
                AppMethodBeat.o(78343);
            }
        } else {
            ab.e(this.TAG, "onGYNetEnd failed errtype:" + i2 + " errcode:" + i3);
            com.tencent.mm.plugin.report.service.h.pYm.a(111, 198, 1, false);
            i.lC((int) this.fEX);
            i.lB((int) this.fEX);
            com.tencent.mm.plugin.report.service.h.pYm.e(10420, new Object[]{Integer.valueOf(i3), Integer.valueOf(1), Long.valueOf(this.startTime), Long.valueOf(bo.anU()), Integer.valueOf(c.bW(ah.getContext())), Integer.valueOf(this.fFb), Integer.valueOf(0)});
            this.ehi.onSceneEnd(i2, i3, str, this);
            if (this.fFv != null) {
                this.fFv.agX();
            }
            AppMethodBeat.o(78343);
        }
    }

    public final void aha() {
        AppMethodBeat.i(78344);
        ab.i(this.TAG, "send img from system");
        this.eFu = true;
        AppMethodBeat.o(78344);
    }

    private boolean a(e eVar, int i, long j, int i2, d dVar) {
        AppMethodBeat.i(78345);
        ab.d(this.TAG, "cdntra clientid:%s start:%d svrid:%d createtime:%d", new Object[]{this.fFa, Integer.valueOf(i), Long.valueOf(j), Integer.valueOf(i2)});
        ab.i(this.TAG, "dkmsgid  set svrmsgid %d -> %d  oriImgLocalId %s imgLocalId %s", new Object[]{Long.valueOf(j), Integer.valueOf(ae.giA), Long.valueOf(this.fEX), Long.valueOf(this.eFm)});
        if (10007 == ae.giz && ae.giA != 0) {
            j = (long) ae.giA;
            ae.giA = 0;
        }
        c(eVar.fDy, i, eVar.frO);
        eVar.setOffset(i);
        eVar.eI(j);
        if (f.b(eVar) && this.fEX != this.eFm) {
            e b = o.ahl().b(Long.valueOf(this.fEX));
            b.eI(j);
            b.lt(eVar.frO);
            b.setOffset(eVar.frO);
            o.ahl().a(Long.valueOf(this.fEX), b);
        }
        if (f.b(eVar)) {
            if (bo.isNullOrNil(this.fFa)) {
                com.tencent.mm.plugin.report.service.h.pYm.e(10420, new Object[]{Integer.valueOf(0), Integer.valueOf(1), Long.valueOf(this.startTime), Long.valueOf(bo.anU()), Integer.valueOf(c.bW(ah.getContext())), Integer.valueOf(this.fFb), Integer.valueOf(eVar.frO - this.startOffset)});
            }
            this.csG.setStatus(2);
            this.csG.eI(j);
            ((j) com.tencent.mm.kernel.g.K(j.class)).bOr().a(this.fDH, this.csG);
            if (com.tencent.mm.modelstat.r.fUq != null) {
                com.tencent.mm.modelstat.r.fUq.j(this.csG);
            }
            if (this.fEZ != null) {
                this.fEZ.fS(0);
            }
            if (r.fGF != null) {
                r.fGF.a(this.eFm, this.csG, this.ehh, this.eFn, this.eFu, dVar);
            }
            if (this.fFv != null) {
                this.fFv.agX();
            }
            this.ehi.onSceneEnd(0, 0, BuildConfig.FLAVOR, this);
            i.lB((int) this.fEX);
            AppMethodBeat.o(78345);
            return false;
        }
        AppMethodBeat.o(78345);
        return true;
    }

    private void c(long j, int i, int i2) {
        AppMethodBeat.i(78346);
        if (this.fEW != null) {
            al.d(new 6(this, j, i2, i));
        }
        AppMethodBeat.o(78346);
    }

    public static void fK(long j) {
        fFD = j;
    }

    public static String sp(String str) {
        AppMethodBeat.i(78347);
        try {
            if (bo.isNullOrNil(str)) {
                AppMethodBeat.o(78347);
            } else {
                String[] split = str.split(",");
                if (split == null || split.length <= 19) {
                    AppMethodBeat.o(78347);
                } else {
                    StringBuilder stringBuilder = new StringBuilder();
                    long j = fFD;
                    fFD = -1;
                    split[19] = stringBuilder.append(j).toString();
                    str = bo.c(bo.P(split), ",");
                    AppMethodBeat.o(78347);
                }
            }
        } catch (Exception e) {
            AppMethodBeat.o(78347);
        }
        return str;
    }
}
