package com.tencent.mm.pluginsdk.g.a.a;

import android.support.v4.f.a;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.kernel.g;
import com.tencent.mm.model.av;
import com.tencent.mm.pluginsdk.g.a.c.d;
import com.tencent.mm.pluginsdk.g.a.c.q;
import com.tencent.mm.pluginsdk.g.a.c.s;
import com.tencent.mm.protocal.protobuf.bsw;
import com.tencent.mm.protocal.protobuf.bzu;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.ytcommon.BuildConfig;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;

public final class b {
    private final d uov;
    private final Set<b> vdO;
    private final k vdP;

    /* synthetic */ b(byte b) {
        this();
    }

    /* Access modifiers changed, original: final */
    public final Set<b> dic() {
        Set<b> newSetFromMap;
        AppMethodBeat.i(79486);
        synchronized (this.vdO) {
            try {
                newSetFromMap = Collections.newSetFromMap(new a(this.vdO.size()));
                newSetFromMap.addAll(this.vdO);
            } finally {
                while (true) {
                }
                AppMethodBeat.o(79486);
            }
        }
        return newSetFromMap;
    }

    public final void as(int i, int i2, int i3) {
        AppMethodBeat.i(79488);
        f(i, i2, i3, true);
        AppMethodBeat.o(79488);
    }

    public static b did() {
        AppMethodBeat.i(138582);
        b dif = c.dif();
        AppMethodBeat.o(138582);
        return dif;
    }

    private b() {
        AppMethodBeat.i(79490);
        this.vdO = Collections.newSetFromMap(new a(i.vep.length));
        this.vdP = new k();
        this.uov = new 3(this);
        q.a.diy().b("CheckResUpdate", this.uov);
        AppMethodBeat.o(79490);
    }

    public static void Ky(int i) {
        AppMethodBeat.i(79491);
        ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "doCheck, resType = %d", new Object[]{Integer.valueOf(i)});
        g.RN();
        boolean QX = com.tencent.mm.kernel.a.QX();
        boolean equals = av.fly.T("login_user_name", BuildConfig.FLAVOR).equals(BuildConfig.FLAVOR);
        if (QX || !equals) {
            g.RO().eJo.a(new m(i), 0);
            AppMethodBeat.o(79491);
            return;
        }
        ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "doCheck, not login, skip");
        AppMethodBeat.o(79491);
    }

    /* Access modifiers changed, original: final */
    public final void b(s sVar) {
        AppMethodBeat.i(79493);
        ab.d("MicroMsg.ResDownloader.CheckResUpdateHelper", "addDecryptRequest, urlkey = " + sVar.field_urlKey);
        k kVar = this.vdP;
        if (kVar.ajd(sVar.field_urlKey)) {
            ab.i("MicroMsg.ResDownloader.CheckResUpdate.DecryptExecutor", "URLKey(%s) is already decrypting, skip repeated task");
            AppMethodBeat.o(79493);
            return;
        }
        kVar.a(a.a(sVar));
        AppMethodBeat.o(79493);
    }

    static void c(s sVar) {
        AppMethodBeat.i(79494);
        ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "performDecryptDirectly, urlkey %s", new Object[]{sVar.field_urlKey});
        k.g(sVar);
        AppMethodBeat.o(79494);
    }

    /* Access modifiers changed, original: final */
    public final void a(int i, bsw bsw, boolean z) {
        AppMethodBeat.i(79495);
        String gN = i.gN(i, bsw.wOI);
        if (bsw.wUV == null) {
            ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "onReceiveDeleteOperation(), resource.Info = null");
            AppMethodBeat.o(79495);
            return;
        }
        ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "receive delete-op, fromNewXml(%b), %d.%d, file version (%d)", new Object[]{Boolean.valueOf(z), Integer.valueOf(i), Integer.valueOf(bsw.wOI), Integer.valueOf(bsw.wUV.wVf)});
        j.z((long) bsw.wUX, 3);
        int i2 = bsw.wUV.wVf;
        q.a.diy().R(new 4(this, gN, i, bsw.wOI, i2, bsw.wUX, bsw.wUY, z));
        AppMethodBeat.o(79495);
    }

    /* Access modifiers changed, original: final */
    public final void b(int i, bsw bsw, boolean z) {
        AppMethodBeat.i(79496);
        String gN = i.gN(i, bsw.wOI);
        if (bsw.wUV == null) {
            ab.e("MicroMsg.ResDownloader.CheckResUpdateHelper", "onReceiveCacheOperation(%s), resource.Info = null, return", new Object[]{gN});
            AppMethodBeat.o(79496);
            return;
        }
        String str;
        String str2 = "MicroMsg.ResDownloader.CheckResUpdateHelper";
        String str3 = "receive cache-op, urlKey = %d.%d,  fromNewXml = %b, file version = %d, eccSignatureList.size = %s, reportId = %s, sampleId = %s, url = %s, data = %s";
        Object[] objArr = new Object[9];
        objArr[0] = Integer.valueOf(i);
        objArr[1] = Integer.valueOf(bsw.wOI);
        objArr[2] = Boolean.valueOf(z);
        objArr[3] = Integer.valueOf(bsw.wUV.wVf);
        if (bsw.wUV.wVh == null) {
            str = "null";
        } else {
            str = String.valueOf(bsw.wUV.wVh.size());
        }
        objArr[4] = str;
        objArr[5] = Integer.valueOf(bsw.wUX);
        objArr[6] = bsw.wUY;
        objArr[7] = bsw.wUV.Url;
        objArr[8] = bsw.wUV.wdt;
        ab.i(str2, str3, objArr);
        if (bsw.wUV.wVh != null) {
            Iterator it = bsw.wUV.wVh.iterator();
            while (it.hasNext()) {
                bzu bzu = (bzu) it.next();
                ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "cache-op, sigInfo: version(%d), signature(%s) ", new Object[]{Integer.valueOf(bzu.Version), bzu.wYR.dlY()});
            }
        }
        j.mc((long) bsw.wUX);
        if (!z) {
            j.z((long) bsw.wUX, 1);
        }
        if (bsw.vQW != 0 && ((long) bsw.vQW) <= bo.anT()) {
            ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "recourse(%s) is expired before do download, expireTime = %d, fileVersion = %d", new Object[]{gN, Integer.valueOf(bsw.vQW), Integer.valueOf(bsw.wUV.wVf)});
            j.z((long) bsw.wUX, 14);
            j.z((long) bsw.wUX, 44);
            j.a(i, bsw.wOI, bsw.wUV.Url, bsw.wUV.wVf, j.a.veG, false, z, false, bsw.wUY);
            AppMethodBeat.o(79496);
        } else if (bo.isNullOrNil(bsw.wUV.Url) && bsw.wUV.wdt == null) {
            ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "cache-op, invalid cache operation, url and data is null or nil, skip");
            AppMethodBeat.o(79496);
        } else {
            g.a aVar = new g.a(bsw.wUV.Url);
            aVar.aja(gN);
            aVar.cut = i;
            aVar.cuu = bsw.wOI;
            aVar.md((long) bsw.vQW);
            aVar.cuv = bsw.wUV.wVf;
            aVar.ajb(bsw.wUV.wdO);
            aVar.vei = i.a.KA(bsw.wUV.wVg);
            aVar.vej = i.a.Kz(bsw.wUV.wVg);
            aVar.vdK = (long) bsw.wUX;
            aVar.vdL = bsw.wUY;
            aVar.KH(bsw.wUZ > 0 ? bsw.wUZ : 3);
            aVar.vek = bsw.vek;
            aVar.KG(bsw.wVa);
            aVar.cuA = z;
            if (!bo.ek(bsw.wUV.wVh)) {
                aVar.vdH = ((bzu) bsw.wUV.wVh.get(0)).wYR.wR;
            }
            if (!(bsw.wUW == null || bo.isNullOrNil(bsw.wUW.wVe))) {
                aVar.vdF = bsw.wUW.wVe;
                aVar.vdG = bsw.wUW.wVd;
            }
            if (bsw.wUV.wdt != null && bsw.wUV.wdt.wR.length > 0) {
                aVar.veh = bsw.wUV.wdt.toByteArray();
            }
            aVar.vdI = bsw.wUV.wVi;
            aVar.fileSize = (long) bsw.wUV.FileSize;
            aVar.KI(bsw.wxG);
            ab.d("MicroMsg.ResDownloader.CheckResUpdateHelper", "request (%s)", new Object[]{aVar.dii().toString()});
            q.a.diy().R(new 5(this, gN, r0));
            AppMethodBeat.o(79496);
        }
    }

    /* Access modifiers changed, original: final */
    public final void a(int i, bsw bsw, boolean z, boolean z2) {
        AppMethodBeat.i(79497);
        String gN = i.gN(i, bsw.wOI);
        if (bsw.wUW == null) {
            ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "onReceiveDecryptOperation(), resource.Key = null");
            AppMethodBeat.o(79497);
        } else if (bo.isNullOrNil(bsw.wUW.wVe)) {
            ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "encryptKey null, skip");
            AppMethodBeat.o(79497);
        } else {
            ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "receive decrypt-op, fromNewXml(%b), %d.%d, key version (%d)", new Object[]{Boolean.valueOf(z), Integer.valueOf(i), Integer.valueOf(bsw.wOI), Integer.valueOf(bsw.wUW.wVd)});
            ab.d("MicroMsg.ResDownloader.CheckResUpdateHelper", "key (%s)", new Object[]{bsw.wUW.wVe});
            j.z((long) bsw.wUX, 4);
            6 6 = new 6(this, gN, bsw.wUV.wVi, bsw.wUW.wVe, bsw.wUW.wVd, bsw.wUX, bsw.wUY, z2);
            if (z2) {
                6.run();
                AppMethodBeat.o(79497);
                return;
            }
            q.a.diy().R(6);
            AppMethodBeat.o(79497);
        }
    }

    public final void f(int i, int i2, int i3, boolean z) {
        AppMethodBeat.i(79487);
        q.a.diy().R(new 1(this, i, i2, i3, z));
        AppMethodBeat.o(79487);
    }

    public static String gM(int i, int i2) {
        AppMethodBeat.i(79492);
        s ajg = q.a.diy().ajg(i.gN(i, i2));
        if (ajg == null) {
            ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "getCachedFilePath, %d.%d, get null info, return", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)});
            AppMethodBeat.o(79492);
            return null;
        }
        ab.v("MicroMsg.ResDownloader.CheckResUpdateHelper", "getCachedFilePath, queried primeInfo { deleted = %b, filepath = %s, md5 = %s, compress = %b, encrypt = %b, originalMd5 = %s }", new Object[]{Boolean.valueOf(ajg.field_deleted), ajg.field_filePath, ajg.field_md5, Boolean.valueOf(ajg.field_fileCompress), Boolean.valueOf(ajg.field_fileEncrypt), ajg.field_originalMd5});
        if (ajg.field_fileCompress || ajg.field_fileEncrypt) {
            String str;
            if (ajg.field_fileCompress) {
                str = ajg.field_filePath + ".decompressed";
            } else if (ajg.field_fileEncrypt) {
                str = ajg.field_filePath + ".decrypted";
            } else {
                str = null;
            }
            if (bo.isNullOrNil(str)) {
                ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "getCachedFilePath, %d.%d, need decrypt or decompress, filePath invalid return null ", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)});
                AppMethodBeat.o(79492);
                return null;
            } else if (bo.isNullOrNil(ajg.field_originalMd5) || !bo.nullAsNil(com.tencent.mm.a.g.cz(str)).equals(ajg.field_originalMd5)) {
                ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "getCachedFilePath, %d.%d, need decrypt, return null ", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)});
                AppMethodBeat.o(79492);
                return null;
            } else {
                ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "getCachedFilePath, %d.%d, need decrypt or decompress, file valid, ret = %s", new Object[]{Integer.valueOf(i), Integer.valueOf(i2), str});
                AppMethodBeat.o(79492);
                return str;
            }
        } else if (ajg.field_deleted || bo.isNullOrNil(ajg.field_filePath) || !bo.nullAsNil(com.tencent.mm.a.g.cz(ajg.field_filePath)).equals(ajg.field_md5)) {
            ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "getCachedFilePath, %d.%d, not need decrypt and file invalid, return null", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)});
            AppMethodBeat.o(79492);
            return null;
        } else {
            ab.i("MicroMsg.ResDownloader.CheckResUpdateHelper", "getCachedFilePath, %d.%d, not need decrypt and file valid, return path(%s)", new Object[]{Integer.valueOf(i), Integer.valueOf(i2), ajg.field_filePath});
            String str2 = ajg.field_filePath;
            AppMethodBeat.o(79492);
            return str2;
        }
    }

    /* Access modifiers changed, original: final */
    public final void e(int i, int i2, String str, int i3) {
        AppMethodBeat.i(79498);
        q.a.diy().R(new 7(this, i, i2, str, i3));
        AppMethodBeat.o(79498);
    }

    /* Access modifiers changed, original: final */
    public final void g(int i, int i2, int i3, boolean z) {
        AppMethodBeat.i(79499);
        if (q.a.diy().handler == null) {
            ab.f("MicroMsg.ResDownloader.CheckResUpdateHelper", "sendEventPreOperation: get null eventThread ");
            AppMethodBeat.o(79499);
            return;
        }
        q.a.diy().handler.post(new 2(this, i3, i, i2, z));
        AppMethodBeat.o(79499);
    }
}
