package com.tencent.mm.plugin.location.ui.impl;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.common.util.CrashUtils.ErrorDialogData;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.bp.d;
import com.tencent.mm.compatible.util.f;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.al;
import com.tencent.mm.sdk.platformtools.at;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.ytcommon.BuildConfig;
import java.lang.ref.WeakReference;
import org.json.JSONArray;
import org.json.JSONObject;

class h$a extends AsyncTask<String, Integer, String> {
    private final WeakReference<Context> nRe;
    private final WeakReference<View> nRf;

    /* Access modifiers changed, original: protected|final|synthetic */
    public final /* synthetic */ Object doInBackground(Object[] objArr) {
        Object obj;
        String obj2;
        AppMethodBeat.i(113709);
        String[] strArr = (String[]) objArr;
        String str = BuildConfig.FLAVOR;
        final Context context = (Context) this.nRe.get();
        if (context != null) {
            if (!at.isNetworkConnected(context)) {
                al.d(new Runnable() {
                    public final void run() {
                        AppMethodBeat.i(113703);
                        Toast.makeText(context, context.getString(2131304039), 0).show();
                        AppMethodBeat.o(113703);
                    }
                });
                ab.e("MicroMsg.TrackMapUI", "fail, network not ready");
                obj2 = str;
            } else if (!f.Mn()) {
                al.d(new Runnable() {
                    public final void run() {
                        AppMethodBeat.i(113704);
                        Toast.makeText(context, context.getString(2131304041), 0).show();
                        AppMethodBeat.o(113704);
                    }
                });
                ab.e("MicroMsg.TrackMapUI", "fail, sdcard not ready");
                obj2 = str;
            } else if (strArr.length == 1) {
                obj2 = Qd(strArr[0]);
            }
            AppMethodBeat.o(113709);
            return obj2;
        }
        obj2 = str;
        AppMethodBeat.o(113709);
        return obj2;
    }

    /* Access modifiers changed, original: protected|final|synthetic */
    public final /* synthetic */ void onPostExecute(Object obj) {
        AppMethodBeat.i(113708);
        String str = (String) obj;
        View view = (View) this.nRf.get();
        if (view != null) {
            view.setVisibility(8);
        }
        Context context = (Context) this.nRe.get();
        if (context == null) {
            AppMethodBeat.o(113708);
            return;
        }
        ab.d("MicroMsg.TrackMapUI", "json string: ".concat(String.valueOf(str)));
        try {
            if (!bo.isNullOrNil(str)) {
                JSONArray optJSONArray = new JSONObject(str).optJSONArray("apkInfos");
                if (optJSONArray != null) {
                    int length = optJSONArray.length();
                    Intent intent = new Intent();
                    for (int i = 0; i < length; i++) {
                        JSONObject optJSONObject = optJSONArray.optJSONObject(i);
                        if (optJSONObject == null) {
                            ab.d("MicroMsg.TrackMapUI", "get json item failure, index: ".concat(String.valueOf(i)));
                        } else if (optJSONObject.optString("cid").equals("00008")) {
                            String optString = optJSONObject.optString("apkPath");
                            long j = 0;
                            String optString2 = optJSONObject.optString("size");
                            if (TextUtils.isDigitsOnly(optString2)) {
                                j = Long.valueOf(optString2).longValue();
                            }
                            ab.d("MicroMsg.TrackMapUI", "url: %s, md5: %s, size: %s", new Object[]{optString, optJSONObject.optString("md5"), Long.valueOf(j)});
                            if (j > 0 && !f.eW(j)) {
                                Toast.makeText(context, context.getString(2131304040), 0).show();
                                ab.e("MicroMsg.TrackMapUI", "fail, not enough space, require size = ".concat(String.valueOf(j)));
                                AppMethodBeat.o(113708);
                                return;
                            } else if (bo.isNullOrNil(optString)) {
                                ab.e("MicroMsg.TrackMapUI", "doAddDownloadTask fail, url is null");
                                AppMethodBeat.o(113708);
                                return;
                            } else {
                                intent.putExtra("task_name", "TencentMap");
                                intent.putExtra("task_url", optString);
                                intent.putExtra("task_size", j);
                                intent.putExtra("file_md5", r5);
                                intent.putExtra("thumb_url", "https://3gimg.qq.com/tencentMapTouch/app/download/wx_android_download_ico.png");
                                intent.putExtra("title", "腾讯地图");
                                intent.addFlags(ErrorDialogData.BINDER_CRASH);
                                d.b(context, "webview", ".ui.tools.WebViewDownloadUI", intent);
                                AppMethodBeat.o(113708);
                                return;
                            }
                        }
                    }
                    AppMethodBeat.o(113708);
                    return;
                }
                ab.d("MicroMsg.TrackMapUI", "get json array failure, key=%s.", new Object[]{"apkInfos"});
                Toast.makeText(context, context.getString(2131304038), 0).show();
            }
            AppMethodBeat.o(113708);
        } catch (Exception e) {
            ab.e("MicroMsg.TrackMapUI", "deal json string failure, msg: %s.", new Object[]{e.getMessage()});
            Toast.makeText(context, context.getString(2131304038), 0).show();
            AppMethodBeat.o(113708);
        }
    }

    h$a(Context context, View view) {
        AppMethodBeat.i(113705);
        this.nRe = new WeakReference(context);
        this.nRf = new WeakReference(view);
        AppMethodBeat.o(113705);
    }

    /* Access modifiers changed, original: protected|final */
    public final void onPreExecute() {
        AppMethodBeat.i(113706);
        View view = (View) this.nRf.get();
        if (view != null) {
            view.setVisibility(0);
        }
        AppMethodBeat.o(113706);
    }

    /* JADX WARNING: Removed duplicated region for block: B:17:0x0066 A:{SYNTHETIC, Splitter:B:17:0x0066} */
    private static java.lang.String Qd(java.lang.String r10) {
        /*
        r9 = 113707; // 0x1bc2b float:1.59337E-40 double:5.61787E-319;
        r8 = 1;
        r7 = 0;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r9);
        r3 = "";
        r2 = 0;
        r0 = new java.net.URL;	 Catch:{ Exception -> 0x004f }
        r0.<init>(r10);	 Catch:{ Exception -> 0x004f }
        r2 = r0.openStream();	 Catch:{ Exception -> 0x004f }
        r0 = 1024; // 0x400 float:1.435E-42 double:5.06E-321;
        r1 = new byte[r0];	 Catch:{ Exception -> 0x004f }
        r4 = r2.read(r1);	 Catch:{ Exception -> 0x004f }
        r0 = new java.lang.String;	 Catch:{ Exception -> 0x004f }
        r0.<init>(r1);	 Catch:{ Exception -> 0x004f }
        r1 = "MicroMsg.TrackMapUI";
        r3 = "json length: ";
        r4 = java.lang.String.valueOf(r4);	 Catch:{ Exception -> 0x009a }
        r3 = r3.concat(r4);	 Catch:{ Exception -> 0x009a }
        com.tencent.mm.sdk.platformtools.ab.d(r1, r3);	 Catch:{ Exception -> 0x009a }
        if (r2 == 0) goto L_0x0038;
    L_0x0035:
        r2.close();	 Catch:{ Exception -> 0x003c }
    L_0x0038:
        com.tencent.matrix.trace.core.AppMethodBeat.o(r9);
        return r0;
    L_0x003c:
        r1 = move-exception;
        r2 = "MicroMsg.TrackMapUI";
        r3 = "download json, close input stream failure, msg: %s.";
        r4 = new java.lang.Object[r8];
        r1 = r1.getMessage();
        r4[r7] = r1;
        com.tencent.mm.sdk.platformtools.ab.e(r2, r3, r4);
        goto L_0x0038;
    L_0x004f:
        r1 = move-exception;
        r0 = r3;
    L_0x0051:
        r3 = "MicroMsg.TrackMapUI";
        r4 = "download failure, msg: %s.";
        r5 = 1;
        r5 = new java.lang.Object[r5];	 Catch:{ all -> 0x007d }
        r6 = 0;
        r1 = r1.getMessage();	 Catch:{ all -> 0x007d }
        r5[r6] = r1;	 Catch:{ all -> 0x007d }
        com.tencent.mm.sdk.platformtools.ab.e(r3, r4, r5);	 Catch:{ all -> 0x007d }
        if (r2 == 0) goto L_0x0038;
    L_0x0066:
        r2.close();	 Catch:{ Exception -> 0x006a }
        goto L_0x0038;
    L_0x006a:
        r1 = move-exception;
        r2 = "MicroMsg.TrackMapUI";
        r3 = "download json, close input stream failure, msg: %s.";
        r4 = new java.lang.Object[r8];
        r1 = r1.getMessage();
        r4[r7] = r1;
        com.tencent.mm.sdk.platformtools.ab.e(r2, r3, r4);
        goto L_0x0038;
    L_0x007d:
        r0 = move-exception;
        if (r2 == 0) goto L_0x0083;
    L_0x0080:
        r2.close();	 Catch:{ Exception -> 0x0087 }
    L_0x0083:
        com.tencent.matrix.trace.core.AppMethodBeat.o(r9);
        throw r0;
    L_0x0087:
        r1 = move-exception;
        r2 = "MicroMsg.TrackMapUI";
        r3 = "download json, close input stream failure, msg: %s.";
        r4 = new java.lang.Object[r8];
        r1 = r1.getMessage();
        r4[r7] = r1;
        com.tencent.mm.sdk.platformtools.ab.e(r2, r3, r4);
        goto L_0x0083;
    L_0x009a:
        r1 = move-exception;
        goto L_0x0051;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.mm.plugin.location.ui.impl.h$a.Qd(java.lang.String):java.lang.String");
    }
}
