package com.tencent.mm.plugin.webview.model;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.i.c;
import com.tencent.mm.i.d;
import com.tencent.mm.i.g.a;
import com.tencent.mm.plugin.webview.modeltools.g;
import com.tencent.mm.protocal.protobuf.azh;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import java.io.ByteArrayOutputStream;

class aj$1 implements a {
    final /* synthetic */ aj umw;

    aj$1(aj ajVar) {
        this.umw = ajVar;
    }

    public final void a(String str, ByteArrayOutputStream byteArrayOutputStream) {
        AppMethodBeat.i(6697);
        ab.i("MicroMsg.WebviewFileChooserCdnService", "getCdnAuthInfo, mediaId = %s", new Object[]{str});
        AppMethodBeat.o(6697);
    }

    public final byte[] l(String str, byte[] bArr) {
        AppMethodBeat.i(6698);
        ab.i("MicroMsg.WebviewFileChooserCdnService", "decodePrepareResponse, mediaId = %s", new Object[]{str});
        AppMethodBeat.o(6698);
        return null;
    }

    public final int a(String str, int i, c cVar, d dVar, boolean z) {
        String str2;
        WebViewJSSDKFileItem webViewJSSDKFileItem;
        AppMethodBeat.i(6699);
        String str3 = "MicroMsg.WebviewFileChooserCdnService";
        String str4 = "on cdn callback mediaId = %s, startRet = %d, keep_ProgressInfo = %s, keep_SceneResult = %s";
        Object[] objArr = new Object[4];
        objArr[0] = str;
        objArr[1] = Integer.valueOf(i);
        objArr[2] = cVar == null ? "null" : cVar.toString();
        if (dVar == null) {
            str2 = "null";
        } else {
            str2 = dVar.toString();
        }
        objArr[3] = str2;
        ab.i(str3, str4, objArr);
        ak cYF = g.cYF();
        if (!bo.isNullOrNil(str)) {
            for (WebViewJSSDKFileItem webViewJSSDKFileItem2 : cYF.umz.values()) {
                if (bo.nullAsNil(webViewJSSDKFileItem2.cHr).equals(str)) {
                    webViewJSSDKFileItem = webViewJSSDKFileItem2;
                    break;
                }
            }
        }
        ab.e("MicroMsg.WebViewJSSDKFileItemManager", "getItemByMediaID error, media id is null or nil");
        webViewJSSDKFileItem = null;
        if (webViewJSSDKFileItem == null) {
            ab.e("MicroMsg.WebviewFileChooserCdnService", "get item by media id failed, media is : %s", new Object[]{str});
            AppMethodBeat.o(6699);
            return 0;
        } else if (i == -21005) {
            ab.i("MicroMsg.WebviewFileChooserCdnService", "duplicate request, ignore this request, media id is %s", new Object[]{str});
            AppMethodBeat.o(6699);
            return 0;
        } else if (i != 0) {
            ab.e("MicroMsg.WebviewFileChooserCdnService", "start failed : %d, media id is :%s", new Object[]{Integer.valueOf(i), str});
            aj.a(this.umw, false, webViewJSSDKFileItem.czD, webViewJSSDKFileItem.cHr, null);
            AppMethodBeat.o(6699);
            return 0;
        } else if (cVar != null) {
            ab.i("MicroMsg.WebviewFileChooserCdnService", "progressInfo : %s", new Object[]{cVar.toString()});
            int i2 = 0;
            if (cVar.field_toltalLength > 0) {
                i2 = (cVar.field_finishedLength * 100) / cVar.field_toltalLength;
            }
            if (i2 < 0) {
                i2 = 0;
            } else if (i2 > 100) {
                i2 = 100;
            }
            this.umw.b(webViewJSSDKFileItem.her, webViewJSSDKFileItem.cyQ, i2, webViewJSSDKFileItem.czD, webViewJSSDKFileItem.cHr);
            AppMethodBeat.o(6699);
            return 0;
        } else {
            if (dVar != null) {
                if (dVar.field_retCode != 0) {
                    ab.e("MicroMsg.WebviewFileChooserCdnService", "cdntra clientid:%s sceneResult.retCode:%d sceneResult[%s]", new Object[]{str, Integer.valueOf(dVar.field_retCode), dVar});
                    aj.a(this.umw, false, webViewJSSDKFileItem.czD, webViewJSSDKFileItem.cHr, null);
                } else {
                    ab.i("MicroMsg.WebviewFileChooserCdnService", "cdn trans suceess, media id : %s", new Object[]{str});
                    if (webViewJSSDKFileItem != null) {
                        webViewJSSDKFileItem.c(dVar);
                        if (webViewJSSDKFileItem.her && webViewJSSDKFileItem.het) {
                            aj ajVar = this.umw;
                            if (webViewJSSDKFileItem == null) {
                                ab.e("MicroMsg.WebviewFileChooserCdnService", "uploadCdnInfo failed, item is null");
                            } else {
                                azh azh = new azh();
                                azh.woO = webViewJSSDKFileItem.umx.field_aesKey;
                                azh.vXd = webViewJSSDKFileItem.umx.field_fileLength;
                                azh.wDs = webViewJSSDKFileItem.umx.field_fileId;
                                azh.type = webViewJSSDKFileItem.cXL();
                                ab.d("MicroMsg.WebviewFileChooserCdnService", "appId:%s, localId:%s, aes_key:%s， file_size:%d, fileId:%s", new Object[]{webViewJSSDKFileItem.appId, webViewJSSDKFileItem.czD, azh.woO, Integer.valueOf(azh.vXd), azh.wDs});
                                azh.wDt = webViewJSSDKFileItem.cXK();
                                com.tencent.mm.kernel.g.Rg().a(1034, ajVar);
                                com.tencent.mm.kernel.g.Rg().a(new ad(webViewJSSDKFileItem.appId, webViewJSSDKFileItem.czD, azh), 0);
                            }
                        } else {
                            aj.a(this.umw, true, webViewJSSDKFileItem.czD, webViewJSSDKFileItem.hep, webViewJSSDKFileItem.umx.field_fileUrl);
                        }
                    }
                }
            }
            AppMethodBeat.o(6699);
            return 0;
        }
    }
}
