package com.tencent.mm.plugin.appbrand.jsapi.i;

import com.google.firebase.analytics.FirebaseAnalytics$b;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.g.a.m;
import com.tencent.mm.plugin.appbrand.jsapi.c;
import com.tencent.mm.plugin.appbrand.jsapi.file.ae;
import com.tencent.mm.plugin.appbrand.l.b;
import com.tencent.mm.plugin.appbrand.l.b.a;
import com.tencent.mm.plugin.appbrand.r.j;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import java.io.File;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONObject;

class d$1 implements a {
    final /* synthetic */ String fYh;
    private JSONObject hRr;
    private JSONArray hRs;
    final /* synthetic */ String hRt;
    final /* synthetic */ d hRu;
    final /* synthetic */ c hxc;

    d$1(d dVar, String str, c cVar, String str2) {
        this.hRu = dVar;
        this.fYh = str;
        this.hxc = cVar;
        this.hRt = str2;
    }

    public final void c(int i, String str, String str2, int i2) {
        AppMethodBeat.i(108021);
        ab.i("MicroMsg.JsApiCreateDownloadTask", "onDownloadResultWithCode errMsg = %d, mimeType = %s, filePath = %s, statusCode = %s", new Object[]{Integer.valueOf(i), str, str2, Integer.valueOf(i2)});
        String ajn;
        if (bo.isNullOrNil(this.fYh)) {
            if (i != b.FAILED) {
                Object obj;
                c cVar = this.hxc;
                ajn = com.tencent.mm.sdk.f.b.ajn(str);
                if (bo.isNullOrNil(ajn) && "audio/mp4".equals(str)) {
                    ajn = "mp4";
                }
                j jVar = new j();
                if (cVar.asE().a(new File(str2), ajn, true, jVar) != com.tencent.mm.plugin.appbrand.appstorage.j.gXA) {
                    obj = null;
                } else {
                    ajn = (String) jVar.value;
                }
                if (obj != null) {
                    ab.i("MicroMsg.JsApiCreateDownloadTask", "onDownloadResultWithCode localId %s", new Object[]{obj});
                    HashMap hashMap = new HashMap();
                    hashMap.put("downloadTaskId", this.hRt);
                    hashMap.put("tempFilePath", obj);
                    hashMap.put("statusCode", Integer.valueOf(i2));
                    hashMap.put("state", FirebaseAnalytics$b.SUCCESS);
                    if (this.hRr != null) {
                        hashMap.put("header", this.hRr);
                    }
                    if (this.hRs != null) {
                        hashMap.put("cookies", this.hRs);
                    }
                    new d.a().j(this.hxc).AM(new JSONObject(hashMap).toString()).aCj();
                    AppMethodBeat.o(108021);
                    return;
                }
            }
            if (d.i(this.hxc, this.hRt)) {
                AppMethodBeat.o(108021);
                return;
            }
            d.a(this.hxc, this.hRt, "download fail");
            AppMethodBeat.o(108021);
            return;
        }
        ajn = ae.a(this.hxc, new File(str2), this.fYh, null);
        if (b.FAILED != i && "ok".equals(ajn)) {
            ab.i("MicroMsg.JsApiCreateDownloadTask", "onDownloadResultWithCode filePath %s", new Object[]{this.fYh});
            HashMap hashMap2 = new HashMap();
            hashMap2.put("downloadTaskId", this.hRt);
            hashMap2.put("filePath", this.fYh);
            hashMap2.put("statusCode", Integer.valueOf(i2));
            hashMap2.put("state", FirebaseAnalytics$b.SUCCESS);
            if (this.hRr != null) {
                hashMap2.put("header", this.hRr);
            }
            if (this.hRs != null) {
                hashMap2.put("cookies", this.hRs);
            }
            new d.a().j(this.hxc).AM(new JSONObject(hashMap2).toString()).aCj();
            AppMethodBeat.o(108021);
        } else if (d.i(this.hxc, this.hRt)) {
            AppMethodBeat.o(108021);
        } else {
            d.a(this.hxc, this.hRt, ajn);
            AppMethodBeat.o(108021);
        }
    }

    public final void g(int i, long j, long j2) {
        AppMethodBeat.i(108022);
        HashMap hashMap = new HashMap();
        hashMap.put("downloadTaskId", this.hRt);
        hashMap.put("state", "progressUpdate");
        hashMap.put("progress", Integer.valueOf(i));
        hashMap.put("totalBytesWritten", Long.valueOf(j));
        hashMap.put("totalBytesExpectedToWrite", Long.valueOf(j2));
        new d.a().j(this.hxc).AM(new JSONObject(hashMap).toString()).aCj();
        AppMethodBeat.o(108022);
    }

    public final void AD(String str) {
        AppMethodBeat.i(108023);
        if (d.i(this.hxc, this.hRt)) {
            AppMethodBeat.o(108023);
            return;
        }
        d.a(this.hxc, this.hRt, str);
        AppMethodBeat.o(108023);
    }

    public final void p(JSONObject jSONObject) {
        AppMethodBeat.i(108024);
        if (jSONObject == null) {
            AppMethodBeat.o(108024);
        } else if (!jSONObject.optBoolean("__AppBrandRemoteDebugRequestHeader__")) {
            this.hRr = jSONObject;
            this.hRs = this.hRr.optJSONArray("cookies");
            HashMap hashMap = new HashMap();
            hashMap.put("downloadTaskId", this.hRt);
            hashMap.put("state", "headersReceived");
            hashMap.put("header", this.hRr);
            if (this.hRs != null) {
                hashMap.put("cookies", this.hRs);
            }
            new d.a().j(this.hxc).AM(new JSONObject(hashMap).toString()).aCj();
            AppMethodBeat.o(108024);
        } else if (((com.tencent.mm.plugin.appbrand.l.a) this.hxc.aa(com.tencent.mm.plugin.appbrand.l.a.class)).bQf) {
            jSONObject.remove("__AppBrandRemoteDebugRequestHeader__");
            m mVar = new m();
            mVar.csn.cso = "download";
            mVar.csn.csq = jSONObject;
            mVar.csn.csp = this.hRt;
            com.tencent.mm.sdk.b.a.xxA.m(mVar);
            AppMethodBeat.o(108024);
        } else {
            AppMethodBeat.o(108024);
        }
    }
}
