翰林优商.apk(点击下载) / BDSHttpRequestMaker.java


package com.baidu.speech.core;

import android.text.TextUtils;
import android.util.Log;
import androidx.core.view.MotionEventCompat;
import com.baidu.mobads.sdk.internal.ae;
import com.baidu.speech.utils.AsrError;
import com.baidu.speech.utils.CommonParam;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import kotlin.UByte;

public class BDSHttpRequestMaker {
    private static final String BACKUP_URL_NORTH = "119.75.222.172";
    private static final String BACKUP_URL_SOUTH = "182.61.62.25";
    private static final int CONNECTION_TIMEOUT = 3;
    private static final Boolean DEBUG = Boolean.FALSE;
    private static final String TAG = "BDSHttpRequestMaker";
    private static final int TIMEOUT_DURATION = 10;
    private static final int TYPE_DOWNLOAD_FINAL = 241;
    private static final int TYPE_DOWNLOAD_FINISH = 243;
    private static final int TYPE_DOWNLOAD_PARTIAL = 240;
    private static final int TYPE_DOWNLOAD_THIRD_DATA = 242;
    private static final int TYPE_UPLOAD_AUDIO = 1;
    private static final int TYPE_UPLOAD_CANCEL = 4;
    private static final int TYPE_UPLOAD_FINISH = 3;
    private static final int TYPE_UPLOAD_PARAM = 0;
    private static final int TYPE_UPLOAD_THIRD_DATA = 2;
    private static SSLSocketFactory defaultSslFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
    private static HostnameVerifier defaulthostVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
    private static String mHostIp = "";
    private static SSLContext sSSLContext = null;
    private final int CONNECTION_STATUS_CLOSE = 2;
    private final int CONNECTION_STATUS_INIT = 0;
    private final int CONNECTION_STATUS_WORKING = 1;
    public final HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
        /* class com.baidu.speech.core.BDSHttpRequestMaker.AnonymousClass1 */

        public boolean verify(String str, SSLSession sSLSession) {
            String convertHostname = BDSHttpRequestMaker.convertHostname(str);
            if (TextUtils.isEmpty(convertHostname)) {
                return false;
            }
            if (Log.isLoggable(BDSHttpRequestMaker.TAG, 3) || BDSHttpRequestMaker.DEBUG.booleanValue()) {
                BDSHttpRequestMaker bDSHttpRequestMaker = BDSHttpRequestMaker.this;
                bDSHttpRequestMaker.logD(BDSHttpRequestMaker.TAG, "hostname : " + str + " verifyUrl : " + convertHostname);
            }
            return convertHostname.equals("vse.baidu.com") || convertHostname.equals("vop.baidu.com") || convertHostname.equals("openapi.baidu.com") || convertHostname.equals("audiotest.baidu.com") || convertHostname.equals(BDSHttpRequestMaker.BACKUP_URL_NORTH) || convertHostname.equals(BDSHttpRequestMaker.BACKUP_URL_SOUTH) || convertHostname.equals("httpsdns.baidu.com") || convertHostname.equals("upl.baidu.com") || convertHostname.contains(".baidu.");
        }
    };
    private boolean mAgentDownload = false;
    private boolean mAgentUpload = false;
    private HttpURLConnection mDownloadConnection = null;
    private int mDownloadConnectionStatus = 0;
    private DataInputStream mDownloadInputStream = null;
    private ArrayList<BDSHTTPResponse> mErrorArray = new ArrayList<>();
    private String mNorthDownUrl;
    private String mNorthUpUrl;
    private boolean mRetriedNorth = false;
    private boolean mRetriedSouth = false;
    private String mSouthDownUrl;
    private String mSouthUpUrl;
    private int mUploadConnctionStatus = 0;
    private HttpURLConnection mUploadConnection = null;
    private OutputStream mUploadOutputStream = null;
    private MyUploadThread mUploadThread = new MyUploadThread();
    private boolean mUploadedData = false;

    public class AudioData {
        public byte[] mData;
        public boolean mIsLast;
        public int mType;

        public AudioData(int i, byte[] bArr, boolean z) {
            this.mType = i;
            this.mIsLast = z;
            int length = bArr.length + 1;
            byte[] bArr2 = {(byte) i};
            byte[] bArr3 = new byte[(length + 4)];
            this.mData = bArr3;
            System.arraycopy(new byte[]{(byte) (length & 255), (byte) ((length >> 8) & 255), (byte) ((length >> 16) & 255), (byte) (length >> 24)}, 0, bArr3, 0, 4);
            System.arraycopy(bArr2, 0, this.mData, 4, 1);
            System.arraycopy(bArr, 0, this.mData, 5, bArr.length);
            if (Log.isLoggable(BDSHttpRequestMaker.TAG, 3) || BDSHttpRequestMaker.DEBUG.booleanValue()) {
                BDSHttpRequestMaker.this.logI(BDSHttpRequestMaker.TAG, "AudioData : mType = " + this.mType + " | mIsLast = " + this.mIsLast + " | mData = " + this.mData.length);
            }
        }
    }

    public class MyDownloadThread extends Thread {
        private MyDownloadThread() {
        }

        public void run() {
        }
    }

    public class MyUploadThread extends Thread {
        private MyUploadThread() {
        }

        public void run() {
        }
    }

    /* access modifiers changed from: private */
    public static String convertHostname(String str) {
        return (str.equals("vse.baidu.com") || str.equals("vop.baidu.com") || str.equals("openapi.baidu.com") || str.equals("upl.baidu.com") || !str.equals(mHostIp)) ? str : CommonParam.REQUEST_URL;
    }

    private void generateBackupUrls(String str, int i) {
        if (1 == i) {
            this.mNorthUpUrl = str.replace(mHostIp, BACKUP_URL_NORTH);
            this.mSouthUpUrl = str.replace(mHostIp, BACKUP_URL_SOUTH);
        } else if (2 == i) {
            this.mNorthDownUrl = str.replace(mHostIp, BACKUP_URL_NORTH);
            this.mSouthDownUrl = str.replace(mHostIp, BACKUP_URL_SOUTH);
        }
    }

    public static BDSHttpRequestMaker newRequestMaker() {
        if (sSSLContext == null) {
            try {
                SSLContext instance = SSLContext.getInstance("TLS");
                sSSLContext = instance;
                instance.init(null, null, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return new BDSHttpRequestMaker();
    }

    private Proxy setAgent() {
        String str = CommonParam.AGENT_URL;
        if (str == "") {
            return null;
        }
        try {
            URL url = new URL(str);
            String hostAddress = InetAddress.getByName(url.getHost()).getHostAddress();
            Log.e(TAG, "ip: " + hostAddress + " port: " + url.getPort());
            return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(url.getHost(), url.getPort()));
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public void cancelRequest() {
        try {
            this.mAgentDownload = false;
            this.mAgentUpload = false;
            HttpURLConnection httpURLConnection = this.mUploadConnection;
            if (httpURLConnection != null) {
                httpURLConnection.disconnect();
                this.mUploadConnection = null;
            }
            HttpURLConnection httpURLConnection2 = this.mDownloadConnection;
            if (httpURLConnection2 != null) {
                httpURLConnection2.disconnect();
                this.mDownloadConnection = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, "BDSHttpRequestMaker cancelRequest exception");
        }
    }

    public void logD(String str, String str2) {
        Log.d(str, str2 + " &" + Integer.toHexString(hashCode()) + ", ");
    }

    public void logI(String str, String str2) {
        Log.i(str, str2 + " &" + Integer.toHexString(hashCode()) + ", ");
    }

    public void logW(String str, String str2) {
        Log.w(str, str2 + " &" + Integer.toHexString(hashCode()) + ", ");
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r13v1, types: [java.net.HttpURLConnection] */
    /* JADX WARN: Type inference failed for: r21v0 */
    /* JADX WARN: Type inference failed for: r21v1, types: [java.io.BufferedInputStream] */
    /* JADX WARN: Type inference failed for: r15v3, types: [java.net.HttpURLConnection] */
    /* JADX WARN: Type inference failed for: r21v2 */
    /* JADX WARN: Type inference failed for: r13v4, types: [java.net.HttpURLConnection] */
    /* JADX WARN: Type inference failed for: r9v5, types: [java.io.BufferedInputStream] */
    /* JADX WARN: Type inference failed for: r9v7 */
    /* JADX WARN: Type inference failed for: r9v8, types: [java.io.BufferedInputStream] */
    /* JADX WARN: Type inference failed for: r15v6, types: [java.net.HttpURLConnection] */
    /* JADX WARN: Type inference failed for: r21v3 */
    /* JADX WARN: Type inference failed for: r9v9 */
    /* JADX WARN: Type inference failed for: r21v4 */
    /* JADX WARN: Type inference failed for: r13v12, types: [java.net.HttpURLConnection] */
    /* JADX WARN: Type inference failed for: r21v5 */
    /* JADX WARN: Type inference failed for: r15v8 */
    /* JADX WARN: Type inference failed for: r21v7 */
    /* JADX WARN: Type inference failed for: r14v16, types: [java.net.URLConnection[]] */
    /* JADX WARN: Type inference failed for: r15v19 */
    /* JADX WARN: Type inference failed for: r21v9 */
    /* JADX WARN: Type inference failed for: r21v10 */
    /* JADX WARN: Type inference failed for: r13v24 */
    /* JADX WARN: Type inference failed for: r13v25 */
    /* JADX WARN: Type inference failed for: r13v26 */
    /* JADX WARN: Type inference failed for: r15v22 */
    /* JADX WARN: Type inference failed for: r13v28 */
    /* JADX WARN: Type inference failed for: r13v29 */
    /* JADX WARNING: Code restructure failed: missing block: B:108:0x028b, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:109:0x028c, code lost:
        r3 = null;
        r1 = r0;
        r21 = null;
        r15 = r13;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:110:0x0293, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:111:0x0294, code lost:
        r3 = null;
        r1 = r0;
        r13 = r13;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:112:0x0297, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:115:0x02a0, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:116:0x02a1, code lost:
        r3 = null;
        r1 = r0;
        r21 = null;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:137:0x02eb, code lost:
        r15.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:140:?, code lost:
        r9.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:141:0x02f4, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:142:0x02f5, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:143:0x02f9, code lost:
        if (r3 != null) goto L_0x037d;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:150:0x030e, code lost:
        com.baidu.speech.utils.LogUtil.d(com.baidu.speech.core.BDSHttpRequestMaker.TAG, "EOF Exception from http connection, trying again...");
        r10 = r10 + 1;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:151:0x0319, code lost:
        if (r13 != 0) goto L_0x031b;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:152:0x031b, code lost:
        r13.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:153:0x031e, code lost:
        if (r13 != 0) goto L_0x0320;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:154:0x0320, code lost:
        r13.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:155:0x0323, code lost:
        if (r9 != 0) goto L_0x0325;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:157:?, code lost:
        r9.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:158:0x0329, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:159:0x032a, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:160:0x032e, code lost:
        if (r3 != null) goto L_0x0330;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:162:?, code lost:
        r3.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:163:0x0334, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:164:0x0335, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:166:0x0346, code lost:
        com.baidu.speech.utils.LogUtil.d(com.baidu.speech.core.BDSHttpRequestMaker.TAG, "EOF Exception from http connection giving up...");
        r6.m_request_status = 2;
        r6.m_http_status = 2000;
        r6.m_log = "error_msg=" + r1.getMessage();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:167:0x036b, code lost:
        if (r13 != 0) goto L_0x036d;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:168:0x036d, code lost:
        r13.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:169:0x0370, code lost:
        if (r9 != 0) goto L_0x0372;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:171:?, code lost:
        r9.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:172:0x0376, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:173:0x0377, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:174:0x037b, code lost:
        if (r3 == null) goto L_0x03ae;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:175:0x037d, code lost:
        r3.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:184:0x0398, code lost:
        r15.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:187:?, code lost:
        r21.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:188:0x03a1, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:189:0x03a2, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:190:0x03a6, code lost:
        if (r3 == null) goto L_0x03ae;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:199:0x03b7, code lost:
        r13.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:202:?, code lost:
        r9.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:203:0x03c0, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:204:0x03c1, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:207:?, code lost:
        r15.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:208:0x03cb, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:209:0x03cc, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:21:0x0077, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:22:0x0078, code lost:
        r1 = r0;
        r15 = r13;
        r3 = null;
        r21 = null;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:23:0x007f, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:24:0x0080, code lost:
        r1 = r0;
        r3 = null;
        r13 = r13;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:28:0x008d, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:29:0x008e, code lost:
        r1 = r0;
        r15 = r13;
        r3 = null;
        r21 = null;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:42:0x00ec, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:57:0x011d, code lost:
        r4.flush();
        r7 = java.lang.System.currentTimeMillis();
        com.baidu.speech.utils.LogUtil.d("End request from java: url: " + r2, new java.lang.String[0]);
        com.baidu.speech.utils.LogUtil.d("http url: " + r2, new java.lang.String[0]);
        r6.m_response_data = r4.toByteArray();
        r6.m_http_status = r13.getResponseCode();
        r6.m_request_status = 0;
        r6.m_log = "connect_time=" + (r19 - r17) + "&request-response_time=" + (r7 - r19);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:58:0x0185, code lost:
        if (android.util.Log.isLoggable(com.baidu.speech.core.BDSHttpRequestMaker.TAG, 3) != false) goto L_0x018f;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:60:0x018d, code lost:
        if (com.baidu.speech.core.BDSHttpRequestMaker.DEBUG.booleanValue() == false) goto L_0x01b4;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:61:0x018f, code lost:
        r1.logD(com.baidu.speech.core.BDSHttpRequestMaker.TAG, "Receive response, data: " + new java.lang.String(r6.m_response_data) + " httpStatus: " + r6.m_http_status);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:63:?, code lost:
        r3 = new java.lang.String(r6.m_response_data);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:64:0x01c1, code lost:
        if (r3.startsWith("license_begin") != false) goto L_0x01d8;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:65:0x01c3, code lost:
        new org.json.JSONObject(r3);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:88:0x025b, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:89:0x025d, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:90:0x025e, code lost:
        r1 = r0;
        r15 = r4;
        r13 = r13;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:91:0x0262, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:92:0x0263, code lost:
        r1 = r0;
        r3 = r4;
        r9 = r9;
        r13 = r13;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:93:0x0267, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:94:0x0268, code lost:
        r22 = r7;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:95:0x026a, code lost:
        r1 = r0;
        r3 = r4;
        r9 = r9;
        r13 = r13;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:96:0x026e, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:97:0x026f, code lost:
        r1 = r0;
        r3 = r4;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Removed duplicated region for block: B:108:0x028b A[ExcHandler: all (r0v25 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:15:0x0066] */
    /* JADX WARNING: Removed duplicated region for block: B:110:0x0293 A[ExcHandler: Exception (r0v24 'e' java.lang.Exception A[CUSTOM_DECLARE]), Splitter:B:15:0x0066] */
    /* JADX WARNING: Removed duplicated region for block: B:115:0x02a0 A[ExcHandler: SocketTimeoutException (r0v21 'e' java.net.SocketTimeoutException A[CUSTOM_DECLARE]), Splitter:B:15:0x0066] */
    /* JADX WARNING: Removed duplicated region for block: B:137:0x02eb  */
    /* JADX WARNING: Removed duplicated region for block: B:139:0x02f0 A[SYNTHETIC, Splitter:B:139:0x02f0] */
    /* JADX WARNING: Removed duplicated region for block: B:150:0x030e  */
    /* JADX WARNING: Removed duplicated region for block: B:184:0x0398  */
    /* JADX WARNING: Removed duplicated region for block: B:186:0x039d A[SYNTHETIC, Splitter:B:186:0x039d] */
    /* JADX WARNING: Removed duplicated region for block: B:199:0x03b7  */
    /* JADX WARNING: Removed duplicated region for block: B:201:0x03bc A[SYNTHETIC, Splitter:B:201:0x03bc] */
    /* JADX WARNING: Removed duplicated region for block: B:206:0x03c7 A[SYNTHETIC, Splitter:B:206:0x03c7] */
    /* JADX WARNING: Removed duplicated region for block: B:211:0x0346 A[SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:21:0x0077 A[Catch:{ SocketTimeoutException -> 0x008d, IOException -> 0x0084, Exception -> 0x007f, all -> 0x0077 }, ExcHandler: all (r0v44 'th' java.lang.Throwable A[CUSTOM_DECLARE, Catch:{ SocketTimeoutException -> 0x008d, IOException -> 0x0084, Exception -> 0x007f, all -> 0x0077 }]), Splitter:B:19:0x006f] */
    /* JADX WARNING: Removed duplicated region for block: B:23:0x007f A[Catch:{ SocketTimeoutException -> 0x008d, IOException -> 0x0084, Exception -> 0x007f, all -> 0x0077 }, ExcHandler: Exception (r0v43 'e' java.lang.Exception A[CUSTOM_DECLARE, Catch:{ SocketTimeoutException -> 0x008d, IOException -> 0x0084, Exception -> 0x007f, all -> 0x0077 }]), Splitter:B:19:0x006f] */
    /* JADX WARNING: Removed duplicated region for block: B:28:0x008d A[Catch:{ SocketTimeoutException -> 0x008d, IOException -> 0x0084, Exception -> 0x007f, all -> 0x0077 }, ExcHandler: SocketTimeoutException (r0v41 'e' java.net.SocketTimeoutException A[CUSTOM_DECLARE, Catch:{ SocketTimeoutException -> 0x008d, IOException -> 0x0084, Exception -> 0x007f, all -> 0x0077 }]), Splitter:B:19:0x006f] */
    /* JADX WARNING: Removed duplicated region for block: B:89:0x025d A[ExcHandler: all (r0v34 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:50:0x0109] */
    /* JADX WARNING: Removed duplicated region for block: B:91:0x0262 A[ExcHandler: Exception (r0v33 'e' java.lang.Exception A[CUSTOM_DECLARE]), Splitter:B:50:0x0109] */
    /* JADX WARNING: Removed duplicated region for block: B:96:0x026e A[ExcHandler: SocketTimeoutException (r0v30 'e' java.net.SocketTimeoutException A[CUSTOM_DECLARE]), Splitter:B:50:0x0109] */
    /* JADX WARNING: Unknown variable types count: 6 */
    public BDSHTTPResponse makeRequest(String str, byte[] bArr, String[] strArr, float f, int i) {
        ByteArrayOutputStream byteArrayOutputStream;
        ?? r13;
        BufferedInputStream bufferedInputStream;
        Throwable th;
        ByteArrayOutputStream byteArrayOutputStream2;
        ByteArrayOutputStream byteArrayOutputStream3;
        BufferedInputStream bufferedInputStream2;
        ByteArrayOutputStream byteArrayOutputStream4;
        ?? r15;
        SocketTimeoutException socketTimeoutException;
        SocketTimeoutException e;
        long j;
        ?? r132;
        BufferedInputStream bufferedInputStream3;
        IOException iOException;
        ByteArrayOutputStream byteArrayOutputStream5;
        IOException e2;
        ByteArrayOutputStream byteArrayOutputStream6;
        BufferedInputStream bufferedInputStream4;
        Exception exc;
        ?? r152;
        Exception e3;
        Throwable th2;
        ?? r133;
        ByteArrayOutputStream byteArrayOutputStream7;
        BDSHttpRequestMaker bDSHttpRequestMaker = this;
        String str2 = str;
        byte[] bArr2 = bArr;
        String[] strArr2 = strArr;
        try {
            mHostIp = new URL(str2).getHost();
        } catch (Exception e4) {
            e4.printStackTrace();
        }
        BDSHTTPResponse bDSHTTPResponse = new BDSHTTPResponse();
        long currentTimeMillis = System.currentTimeMillis();
        char c = 0;
        int i2 = 0;
        loop0:
        while (true) {
            if (Log.isLoggable(TAG, 3) || DEBUG.booleanValue()) {
                bDSHttpRequestMaker.logD(TAG, "Begin request, url is " + str2);
            }
            try {
                if (System.currentTimeMillis() - currentTimeMillis <= 500) {
                    URL url = new URL(str2);
                    long currentTimeMillis2 = System.currentTimeMillis();
                    r133 = (HttpURLConnection) url.openConnection();
                    try {
                        long currentTimeMillis3 = System.currentTimeMillis();
                        if (r133 instanceof HttpsURLConnection) {
                            try {
                                ((HttpsURLConnection) r133).setHostnameVerifier(bDSHttpRequestMaker.DO_NOT_VERIFY);
                            } catch (SocketTimeoutException e5) {
                            } catch (IOException e6) {
                                e = e6;
                                iOException = e;
                                j = currentTimeMillis;
                                byteArrayOutputStream3 = null;
                                byteArrayOutputStream5 = r133;
                                bufferedInputStream3 = byteArrayOutputStream3;
                                r132 = byteArrayOutputStream5;
                                iOException.printStackTrace();
                                if (i2 < 30) {
                                }
                            } catch (Exception e7) {
                            } catch (Throwable th3) {
                            }
                        }
                        int i3 = 0;
                        while (strArr2 != null && i3 < strArr2.length - 1) {
                            r133.setRequestProperty(strArr2[i3], strArr2[i3 + 1]);
                            i3 += 2;
                        }
                        r133.setDoInput(true);
                        if (i != 1 || bArr2 == null) {
                            int i4 = (int) (1000.0f * f);
                            r133.setConnectTimeout(i4);
                            r133.setReadTimeout(i4);
                        } else {
                            r133.setDoOutput(true);
                            r133.setFixedLengthStreamingMode(bArr2.length);
                            r133.setReadTimeout(10000);
                            r133.setConnectTimeout(8000);
                            final ?? r14 = new URLConnection[1];
                            r14[c] = r133;
                            Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
                                /* class com.baidu.speech.core.BDSHttpRequestMaker.AnonymousClass2 */

                                @Override // java.util.concurrent.Callable
                                public Void call() {
                                    r14[0].connect();
                                    return null;
                                }
                            }).get(10, TimeUnit.SECONDS);
                            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(r133.getOutputStream());
                            bufferedOutputStream.write(bArr2);
                            bufferedOutputStream.close();
                        }
                        bufferedInputStream = new BufferedInputStream(r133.getInputStream());
                    } catch (SocketTimeoutException e8) {
                    } catch (IOException e9) {
                        IOException e10 = e9;
                        j = currentTimeMillis;
                        byteArrayOutputStream3 = null;
                        iOException = e10;
                        byteArrayOutputStream5 = r133;
                        bufferedInputStream3 = byteArrayOutputStream3;
                        r132 = byteArrayOutputStream5;
                        iOException.printStackTrace();
                        if (i2 < 30) {
                        }
                    } catch (Exception e11) {
                    } catch (Throwable th4) {
                    }
                    try {
                        byteArrayOutputStream7 = new ByteArrayOutputStream();
                        try {
                            byte[] bArr3 = new byte[16384];
                            while (true) {
                                j = currentTimeMillis;
                                int read = bufferedInputStream.read(bArr3, 0, 16384);
                                if (read == -1) {
                                    break loop0;
                                }
                                byteArrayOutputStream7.write(bArr3, 0, read);
                                currentTimeMillis = j;
                            }
                        } catch (Exception e12) {
                            e12.printStackTrace();
                            bDSHTTPResponse.m_http_status = 2006;
                            bDSHTTPResponse.m_response_data = null;
                            bDSHTTPResponse.m_request_status = 0;
                        } catch (Throwable th5) {
                        }
                    } catch (SocketTimeoutException e13) {
                        byteArrayOutputStream3 = null;
                        socketTimeoutException = e13;
                        bufferedInputStream2 = bufferedInputStream;
                        r15 = r133;
                        try {
                            socketTimeoutException.printStackTrace();
                            bDSHTTPResponse.m_http_status = 2005;
                            bDSHTTPResponse.m_request_status = 0;
                            if (r15 != 0) {
                            }
                            if (bufferedInputStream2 != null) {
                            }
                        } catch (Throwable th6) {
                            th = th6;
                            byteArrayOutputStream4 = r15;
                            byteArrayOutputStream2 = byteArrayOutputStream4;
                            bufferedInputStream = bufferedInputStream2;
                            byteArrayOutputStream = byteArrayOutputStream3;
                            r13 = byteArrayOutputStream2;
                            if (r13 != 0) {
                            }
                            if (bufferedInputStream != null) {
                            }
                            if (byteArrayOutputStream != null) {
                            }
                            throw th;
                        }
                    } catch (IOException e14) {
                        j = currentTimeMillis;
                        byteArrayOutputStream3 = null;
                        iOException = e14;
                        bufferedInputStream3 = bufferedInputStream;
                        r132 = r133;
                        iOException.printStackTrace();
                        if (i2 < 30) {
                        }
                    } catch (Exception e15) {
                        byteArrayOutputStream3 = null;
                        exc = e15;
                        bufferedInputStream4 = bufferedInputStream;
                        byteArrayOutputStream6 = r133;
                        r152 = byteArrayOutputStream6;
                        try {
                            exc.printStackTrace();
                            bDSHTTPResponse.m_http_status = 2000;
                            bDSHTTPResponse.m_request_status = 2;
                            bDSHTTPResponse.m_log = "error_msg=" + exc.getMessage();
                            if (r152 != 0) {
                            }
                            if (bufferedInputStream4 != 0) {
                            }
                        } catch (Throwable th7) {
                            th = th7;
                            bufferedInputStream2 = bufferedInputStream4;
                            byteArrayOutputStream4 = r152;
                            byteArrayOutputStream2 = byteArrayOutputStream4;
                            bufferedInputStream = bufferedInputStream2;
                            byteArrayOutputStream = byteArrayOutputStream3;
                            r13 = byteArrayOutputStream2;
                            if (r13 != 0) {
                            }
                            if (bufferedInputStream != null) {
                            }
                            if (byteArrayOutputStream != null) {
                            }
                            throw th;
                        }
                    } catch (Throwable th8) {
                        byteArrayOutputStream3 = null;
                        th = th8;
                        byteArrayOutputStream2 = r133;
                        byteArrayOutputStream = byteArrayOutputStream3;
                        r13 = byteArrayOutputStream2;
                        if (r13 != 0) {
                        }
                        if (bufferedInputStream != null) {
                        }
                        if (byteArrayOutputStream != null) {
                        }
                        throw th;
                    }
                } else {
                    j = currentTimeMillis;
                    byteArrayOutputStream3 = null;
                    try {
                        throw new SocketTimeoutException();
                    } catch (SocketTimeoutException e16) {
                        e = e16;
                        socketTimeoutException = e;
                        ByteArrayOutputStream byteArrayOutputStream8 = byteArrayOutputStream3;
                        bufferedInputStream2 = byteArrayOutputStream8;
                        r15 = byteArrayOutputStream8;
                        socketTimeoutException.printStackTrace();
                        bDSHTTPResponse.m_http_status = 2005;
                        bDSHTTPResponse.m_request_status = 0;
                        if (r15 != 0) {
                        }
                        if (bufferedInputStream2 != null) {
                        }
                    } catch (IOException e17) {
                        e2 = e17;
                        iOException = e2;
                        byteArrayOutputStream5 = byteArrayOutputStream3;
                        bufferedInputStream3 = byteArrayOutputStream3;
                        r132 = byteArrayOutputStream5;
                        iOException.printStackTrace();
                        if (i2 < 30) {
                        }
                    } catch (Exception e18) {
                        e3 = e18;
                        exc = e3;
                        ByteArrayOutputStream byteArrayOutputStream9 = byteArrayOutputStream3;
                        bufferedInputStream4 = byteArrayOutputStream3;
                        byteArrayOutputStream6 = byteArrayOutputStream9;
                        r152 = byteArrayOutputStream6;
                        exc.printStackTrace();
                        bDSHTTPResponse.m_http_status = 2000;
                        bDSHTTPResponse.m_request_status = 2;
                        bDSHTTPResponse.m_log = "error_msg=" + exc.getMessage();
                        if (r152 != 0) {
                        }
                        if (bufferedInputStream4 != 0) {
                        }
                    } catch (Throwable th9) {
                        th2 = th9;
                        th = th2;
                        ByteArrayOutputStream byteArrayOutputStream10 = byteArrayOutputStream3;
                        bufferedInputStream2 = byteArrayOutputStream10;
                        byteArrayOutputStream4 = byteArrayOutputStream10;
                        byteArrayOutputStream2 = byteArrayOutputStream4;
                        bufferedInputStream = bufferedInputStream2;
                        byteArrayOutputStream = byteArrayOutputStream3;
                        r13 = byteArrayOutputStream2;
                        if (r13 != 0) {
                        }
                        if (bufferedInputStream != null) {
                        }
                        if (byteArrayOutputStream != null) {
                        }
                        throw th;
                    }
                }
            } catch (SocketTimeoutException e19) {
                e = e19;
                byteArrayOutputStream3 = null;
                socketTimeoutException = e;
                ByteArrayOutputStream byteArrayOutputStream82 = byteArrayOutputStream3;
                bufferedInputStream2 = byteArrayOutputStream82;
                r15 = byteArrayOutputStream82;
                socketTimeoutException.printStackTrace();
                bDSHTTPResponse.m_http_status = 2005;
                bDSHTTPResponse.m_request_status = 0;
                if (r15 != 0) {
                }
                if (bufferedInputStream2 != null) {
                }
            } catch (IOException e20) {
                e2 = e20;
                j = currentTimeMillis;
                byteArrayOutputStream3 = null;
                iOException = e2;
                byteArrayOutputStream5 = byteArrayOutputStream3;
                bufferedInputStream3 = byteArrayOutputStream3;
                r132 = byteArrayOutputStream5;
                iOException.printStackTrace();
                if (i2 < 30) {
                }
            } catch (Exception e21) {
                e3 = e21;
                byteArrayOutputStream3 = null;
                exc = e3;
                ByteArrayOutputStream byteArrayOutputStream92 = byteArrayOutputStream3;
                bufferedInputStream4 = byteArrayOutputStream3;
                byteArrayOutputStream6 = byteArrayOutputStream92;
                r152 = byteArrayOutputStream6;
                exc.printStackTrace();
                bDSHTTPResponse.m_http_status = 2000;
                bDSHTTPResponse.m_request_status = 2;
                bDSHTTPResponse.m_log = "error_msg=" + exc.getMessage();
                if (r152 != 0) {
                }
                if (bufferedInputStream4 != 0) {
                }
            } catch (Throwable th10) {
                th2 = th10;
                byteArrayOutputStream3 = null;
                th = th2;
                ByteArrayOutputStream byteArrayOutputStream102 = byteArrayOutputStream3;
                bufferedInputStream2 = byteArrayOutputStream102;
                byteArrayOutputStream4 = byteArrayOutputStream102;
                byteArrayOutputStream2 = byteArrayOutputStream4;
                bufferedInputStream = bufferedInputStream2;
                byteArrayOutputStream = byteArrayOutputStream3;
                r13 = byteArrayOutputStream2;
                if (r13 != 0) {
                }
                if (bufferedInputStream != null) {
                }
                if (byteArrayOutputStream != null) {
                }
                throw th;
            }
            bDSHttpRequestMaker = this;
            str2 = str;
            bArr2 = bArr;
            strArr2 = strArr;
            currentTimeMillis = j;
            c = 0;
        }
        return bDSHTTPResponse;
        try {
            byteArrayOutputStream7.close();
        } catch (IOException e22) {
            e22.printStackTrace();
        }
        return bDSHTTPResponse;
        Map<String, List<String>> headerFields = r133.getHeaderFields();
        if (headerFields.entrySet().size() > 0) {
            bDSHTTPResponse.m_response_headers = new String[(headerFields.entrySet().size() * 2)];
            int i5 = 0;
            for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) {
                int i6 = i5 + 1;
                String str3 = "";
                bDSHTTPResponse.m_response_headers[i5] = entry.getKey() != null ? entry.getKey() : str3;
                String[] strArr3 = bDSHTTPResponse.m_response_headers;
                int i7 = i6 + 1;
                if (entry.getValue().get(0) != null) {
                    str3 = entry.getValue().get(0);
                }
                strArr3[i6] = str3;
                i5 = i7;
            }
        }
        r133.disconnect();
        try {
            bufferedInputStream.close();
        } catch (IOException e23) {
            e23.printStackTrace();
        }
        byteArrayOutputStream7.close();
        return bDSHTTPResponse;
    }

    /* JADX WARNING: Removed duplicated region for block: B:63:0x0178 A[RETURN] */
    public BDSHTTPResponse readData() {
        BDSHTTPResponse bDSHTTPResponse;
        BDSHTTPResponse bDSHTTPResponse2;
        Exception e;
        if (this.mDownloadConnectionStatus == 2) {
            logW(TAG, "Download connection stauts has already been closed.");
            return null;
        }
        if (this.mErrorArray.size() <= 0) {
            try {
                if (this.mDownloadInputStream == null) {
                    this.mDownloadInputStream = new DataInputStream(this.mDownloadConnection.getInputStream());
                }
                byte[] bArr = new byte[4];
                this.mDownloadInputStream.readFully(bArr, 0, 4);
                int i = (bArr[0] & 255) | ((bArr[1] << 8) & MotionEventCompat.ACTION_POINTER_INDEX_MASK) | ((bArr[2] << 24) >>> 8) | (bArr[3] << 24);
                byte readByte = this.mDownloadInputStream.readByte();
                int i2 = readByte & UByte.MAX_VALUE;
                if (243 == i2) {
                    this.mUploadConnctionStatus = 2;
                    this.mDownloadConnectionStatus = 2;
                }
                if (Log.isLoggable(TAG, 3) || DEBUG.booleanValue()) {
                    logI(TAG, "readData dataType : " + i2 + " " + this.mDownloadConnection.getURL());
                }
                if (i <= 1) {
                    byte[] bArr2 = new byte[5];
                    System.arraycopy(bArr, 0, bArr2, 0, 4);
                    bArr2[4] = readByte;
                    bDSHTTPResponse = new BDSHTTPResponse();
                    bDSHTTPResponse.m_http_status = 200;
                    bDSHTTPResponse.m_response_data = bArr2;
                } else if (i > 67584) {
                    BDSHTTPResponse bDSHTTPResponse3 = new BDSHTTPResponse();
                    bDSHTTPResponse3.m_http_status = 2006;
                    bDSHTTPResponse3.m_response_data = null;
                    bDSHTTPResponse3.m_request_status = 0;
                    this.mErrorArray.add(bDSHTTPResponse3);
                    return bDSHTTPResponse3;
                } else {
                    int i3 = i - 1;
                    byte[] bArr3 = new byte[i3];
                    int i4 = 0;
                    while (i4 < i3) {
                        i4 += this.mDownloadInputStream.read(bArr3, i4, i3 - i4);
                    }
                    String str = new String(bArr3);
                    if (Log.isLoggable(TAG, 3) || DEBUG.booleanValue()) {
                        logI(TAG, "response : " + str + " " + this.mDownloadConnection.getURL());
                    }
                    byte[] bArr4 = new byte[(i + 4)];
                    System.arraycopy(bArr, 0, bArr4, 0, 4);
                    bArr4[4] = readByte;
                    if (i3 > 0) {
                        System.arraycopy(bArr3, 0, bArr4, 5, i3);
                    }
                    bDSHTTPResponse = new BDSHTTPResponse();
                    try {
                        bDSHTTPResponse.m_http_status = 200;
                        bDSHTTPResponse.m_response_data = bArr4;
                    } catch (SocketTimeoutException unused) {
                    } catch (SSLException unused2) {
                        bDSHTTPResponse2 = new BDSHTTPResponse();
                        logI(TAG, "SSLException");
                        bDSHTTPResponse2.m_http_status = 2100;
                        bDSHTTPResponse2.m_response_data = null;
                        bDSHTTPResponse2.m_request_status = 0;
                        this.mErrorArray.add(bDSHTTPResponse2);
                        if (this.mErrorArray.size() <= 0) {
                        }
                        BDSHTTPResponse bDSHTTPResponse4 = this.mErrorArray.get(0);
                        this.mErrorArray.clear();
                        return bDSHTTPResponse4;
                    } catch (Exception e2) {
                        e = e2;
                        logI(TAG, "Exception");
                        e.printStackTrace();
                        bDSHTTPResponse2 = new BDSHTTPResponse();
                        bDSHTTPResponse2.m_http_status = 2100;
                        bDSHTTPResponse2.m_response_data = null;
                        bDSHTTPResponse2.m_request_status = 0;
                        this.mErrorArray.add(bDSHTTPResponse2);
                        if (this.mErrorArray.size() <= 0) {
                        }
                        BDSHTTPResponse bDSHTTPResponse42 = this.mErrorArray.get(0);
                        this.mErrorArray.clear();
                        return bDSHTTPResponse42;
                    }
                }
                bDSHTTPResponse.m_request_status = 0;
            } catch (SocketTimeoutException unused3) {
                bDSHTTPResponse = null;
                bDSHTTPResponse2 = new BDSHTTPResponse();
                bDSHTTPResponse2.m_http_status = this.mAgentDownload ? AsrError.ERROR_NETWORK_FAIL_AGENT_READ_DOWN : 2005;
                bDSHTTPResponse2.m_response_data = null;
                bDSHTTPResponse2.m_request_status = 0;
                this.mAgentDownload = false;
                this.mErrorArray.add(bDSHTTPResponse2);
                if (this.mErrorArray.size() <= 0) {
                }
                BDSHTTPResponse bDSHTTPResponse422 = this.mErrorArray.get(0);
                this.mErrorArray.clear();
                return bDSHTTPResponse422;
            } catch (SSLException unused4) {
                bDSHTTPResponse = null;
                bDSHTTPResponse2 = new BDSHTTPResponse();
                logI(TAG, "SSLException");
                bDSHTTPResponse2.m_http_status = 2100;
                bDSHTTPResponse2.m_response_data = null;
                bDSHTTPResponse2.m_request_status = 0;
                this.mErrorArray.add(bDSHTTPResponse2);
                if (this.mErrorArray.size() <= 0) {
                }
                BDSHTTPResponse bDSHTTPResponse4222 = this.mErrorArray.get(0);
                this.mErrorArray.clear();
                return bDSHTTPResponse4222;
            } catch (Exception e3) {
                e = e3;
                bDSHTTPResponse = null;
                logI(TAG, "Exception");
                e.printStackTrace();
                bDSHTTPResponse2 = new BDSHTTPResponse();
                bDSHTTPResponse2.m_http_status = 2100;
                bDSHTTPResponse2.m_response_data = null;
                bDSHTTPResponse2.m_request_status = 0;
                this.mErrorArray.add(bDSHTTPResponse2);
                if (this.mErrorArray.size() <= 0) {
                }
                BDSHTTPResponse bDSHTTPResponse42222 = this.mErrorArray.get(0);
                this.mErrorArray.clear();
                return bDSHTTPResponse42222;
            }
            if (this.mErrorArray.size() <= 0) {
                return bDSHTTPResponse;
            }
        }
        BDSHTTPResponse bDSHTTPResponse422222 = this.mErrorArray.get(0);
        this.mErrorArray.clear();
        return bDSHTTPResponse422222;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:26:0x007f, code lost:
        r7 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:27:0x0080, code lost:
        r7.printStackTrace();
        r7 = new com.baidu.speech.core.BDSHTTPResponse();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:28:0x008a, code lost:
        if (r6.mAgentUpload != false) goto L_0x008c;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:29:0x008c, code lost:
        r8 = com.baidu.speech.utils.AsrError.ERROR_NETWORK_FAIL_AGENT_READ_UP;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:30:0x008f, code lost:
        r8 = 2003;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:31:0x0091, code lost:
        r7.m_http_status = r8;
        r7.m_response_data = null;
        r7.m_request_status = 0;
        r6.mErrorArray.add(r7);
        r6.mAgentUpload = false;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:33:0x009f, code lost:
        logW(com.baidu.speech.core.BDSHttpRequestMaker.TAG, "send data EOFException");
        r7 = new com.baidu.speech.core.BDSHTTPResponse();
        r7.m_http_status = 2100;
        r7.m_response_data = null;
        r7.m_request_status = 0;
        r6.mErrorArray.add(r7);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:35:0x00b6, code lost:
        return -1;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Removed duplicated region for block: B:26:0x007f A[ExcHandler: Exception (r7v3 'e' java.lang.Exception A[CUSTOM_DECLARE]), Splitter:B:10:0x0046] */
    public int sendData(byte[] bArr, boolean z) {
        if (this.mUploadConnctionStatus == 2) {
            logW(TAG, "Upload connection stauts has already been closed.");
            return 0;
        }
        int i = bArr[4] & UByte.MAX_VALUE;
        if (Log.isLoggable(TAG, 3) || DEBUG.booleanValue()) {
            logI(TAG, "sendData  dataType : " + i + " " + this.mUploadConnection.getURL());
        }
        try {
            HttpURLConnection httpURLConnection = this.mUploadConnection;
            if (httpURLConnection == null) {
                Log.e(TAG, "Upload conncetion not exist");
                return -1;
            }
            if (this.mUploadOutputStream == null) {
                this.mUploadOutputStream = httpURLConnection.getOutputStream();
            }
            this.mUploadOutputStream.write(bArr);
            this.mUploadOutputStream.flush();
            if (z) {
                this.mUploadOutputStream.close();
                this.mUploadConnection.getInputStream().close();
                this.mUploadConnection.disconnect();
            }
            return 0;
        } catch (EOFException e) {
            e.printStackTrace();
        } catch (Exception e2) {
        }
    }

    public int setupConnection(String str, String[] strArr, float f, int i) {
        if (Log.isLoggable(TAG, 3) || DEBUG.booleanValue()) {
            logI(TAG, "url = " + str);
        }
        this.mErrorArray.clear();
        try {
            mHostIp = new URL(str).getHost();
            if (Log.isLoggable(TAG, 3) || DEBUG.booleanValue()) {
                logD(TAG, "url: " + str + " mHostIp: " + mHostIp);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (str.contains("up")) {
            generateBackupUrls(str, 1);
            return setupUploadConnection(str, strArr, f, i);
        } else if (str.contains("down")) {
            generateBackupUrls(str, 2);
            return setupDownloadConnection(str, strArr, f, i);
        } else {
            Log.e(TAG, "Error url : " + str);
            return -1;
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:33:0x00eb  */
    /* JADX WARNING: Removed duplicated region for block: B:35:0x00f0  */
    public int setupDownloadConnection(String str, String[] strArr, float f, int i) {
        String str2;
        try {
            Proxy agent = setAgent();
            if (agent != null) {
                this.mDownloadConnection = (HttpURLConnection) new URL(str).openConnection(agent);
                this.mAgentDownload = true;
            } else {
                this.mDownloadConnection = (HttpURLConnection) new URL(str).openConnection();
            }
            HttpURLConnection httpURLConnection = this.mDownloadConnection;
            if (httpURLConnection instanceof HttpsURLConnection) {
                ((HttpsURLConnection) httpURLConnection).setHostnameVerifier(this.DO_NOT_VERIFY);
            }
            this.mDownloadConnection.setConnectTimeout(3000);
            this.mDownloadConnection.setReadTimeout(10000);
            this.mDownloadConnection.setRequestMethod(ae.b);
            int i2 = 0;
            while (strArr != null && i2 < strArr.length - 1) {
                this.mDownloadConnection.setRequestProperty(strArr[i2], strArr[i2 + 1]);
                i2 += 2;
            }
            this.mDownloadConnection.setRequestProperty("Connection", "close");
            this.mDownloadConnection.setChunkedStreamingMode(0);
            this.mDownloadConnection.connect();
            this.mDownloadConnectionStatus = 1;
            AudioData audioData = new AudioData(3, new byte[0], true);
            OutputStream outputStream = this.mDownloadConnection.getOutputStream();
            outputStream.write(audioData.mData);
            outputStream.flush();
            outputStream.close();
            if (Log.isLoggable(TAG, 3) || DEBUG.booleanValue()) {
                for (int i3 = 0; i3 < audioData.mData.length; i3++) {
                    logI(TAG, "DownloadThread mData[" + i3 + "] = " + Integer.toHexString(audioData.mData[i3] & UByte.MAX_VALUE));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            if (!this.mRetriedNorth) {
                this.mRetriedNorth = true;
                str2 = this.mNorthDownUrl;
            } else {
                if (!this.mRetriedSouth) {
                    this.mRetriedSouth = true;
                    str2 = this.mSouthDownUrl;
                }
                BDSHTTPResponse bDSHTTPResponse = new BDSHTTPResponse();
                bDSHTTPResponse.m_http_status = !(e instanceof SocketTimeoutException) ? 1005 : this.mAgentDownload ? AsrError.ERROR_NETWORK_FAIL_AGENT_CONNECT_DOWN : 2004;
                bDSHTTPResponse.m_response_data = null;
                bDSHTTPResponse.m_request_status = 0;
                this.mErrorArray.add(bDSHTTPResponse);
                this.mAgentDownload = false;
            }
            setupDownloadConnection(str2, strArr, f, i);
            BDSHTTPResponse bDSHTTPResponse2 = new BDSHTTPResponse();
            bDSHTTPResponse2.m_http_status = !(e instanceof SocketTimeoutException) ? 1005 : this.mAgentDownload ? AsrError.ERROR_NETWORK_FAIL_AGENT_CONNECT_DOWN : 2004;
            bDSHTTPResponse2.m_response_data = null;
            bDSHTTPResponse2.m_request_status = 0;
            this.mErrorArray.add(bDSHTTPResponse2);
            this.mAgentDownload = false;
        }
        return 0;
    }

    /* JADX WARNING: Removed duplicated region for block: B:25:0x0094  */
    /* JADX WARNING: Removed duplicated region for block: B:27:0x0099  */
    public int setupUploadConnection(String str, String[] strArr, float f, int i) {
        int i2;
        String str2;
        try {
            Proxy agent = setAgent();
            if (agent != null) {
                this.mUploadConnection = (HttpURLConnection) new URL(str).openConnection(agent);
                this.mAgentUpload = true;
            } else {
                this.mUploadConnection = (HttpURLConnection) new URL(str).openConnection();
            }
            HttpURLConnection httpURLConnection = this.mUploadConnection;
            if (httpURLConnection instanceof HttpsURLConnection) {
                ((HttpsURLConnection) httpURLConnection).setHostnameVerifier(this.DO_NOT_VERIFY);
            }
            this.mUploadConnection.setConnectTimeout(3000);
            this.mUploadConnection.setReadTimeout(10000);
            this.mUploadConnection.setRequestMethod(ae.b);
            int i3 = 0;
            while (strArr != null && i3 < strArr.length - 1) {
                this.mUploadConnection.setRequestProperty(strArr[i3], strArr[i3 + 1]);
                i3 += 2;
            }
            this.mUploadConnection.setRequestProperty("Connection", "close");
            this.mUploadConnection.setChunkedStreamingMode(0);
            this.mUploadConnection.connect();
            this.mUploadConnctionStatus = 1;
        } catch (Exception e) {
            e.printStackTrace();
            if (!this.mRetriedNorth) {
                this.mRetriedNorth = true;
                str2 = this.mNorthUpUrl;
            } else {
                if (!this.mRetriedSouth) {
                    this.mRetriedSouth = true;
                    str2 = this.mSouthUpUrl;
                }
                BDSHTTPResponse bDSHTTPResponse = new BDSHTTPResponse();
                if (!(e instanceof SocketTimeoutException)) {
                    i2 = 1003;
                } else if (this.mAgentUpload) {
                    i2 = 2002;
                } else {
                    bDSHTTPResponse.m_request_status = AsrError.ERROR_NETWORK_FAIL_AGENT_CONNECT_UP;
                    this.mAgentUpload = false;
                    bDSHTTPResponse.m_response_data = null;
                    bDSHTTPResponse.m_request_status = 0;
                    this.mErrorArray.add(bDSHTTPResponse);
                }
                bDSHTTPResponse.m_http_status = i2;
                this.mAgentUpload = false;
                bDSHTTPResponse.m_response_data = null;
                bDSHTTPResponse.m_request_status = 0;
                this.mErrorArray.add(bDSHTTPResponse);
            }
            setupUploadConnection(str2, strArr, f, i);
            BDSHTTPResponse bDSHTTPResponse2 = new BDSHTTPResponse();
            if (!(e instanceof SocketTimeoutException)) {
            }
            bDSHTTPResponse2.m_http_status = i2;
            this.mAgentUpload = false;
            bDSHTTPResponse2.m_response_data = null;
            bDSHTTPResponse2.m_request_status = 0;
            this.mErrorArray.add(bDSHTTPResponse2);
        }
        return 0;
    }
}