智能工厂.apk(点击下载) / BDSHttpRequestMaker.java


package com.baidu.speech.core;

import android.util.Log;
import androidx.core.view.MotionEventCompat;
import com.baidu.speech.utils.AsrError;
import com.baidu.speech.utils.CommonParam;
import com.baidu.speech.utils.LogUtil;
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter;
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 org.altbeacon.bluetooth.Pdu;
import org.json.JSONObject;

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 = true;
    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;
    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 (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;

    /* access modifiers changed from: private */
    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;
            this.mData = new byte[(length + 4)];
            System.arraycopy(new byte[]{(byte) (length & 255), (byte) ((length >> 8) & 255), (byte) ((length >> 16) & 255), (byte) (length >> 24)}, 0, this.mData, 0, 4);
            System.arraycopy(new byte[]{(byte) i}, 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);
            }
        }
    }

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

        public void run() {
        }
    }

    private 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 {
                sSSLContext = SSLContext.getInstance("TLS");
                sSSLContext.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;
            if (this.mUploadConnection != null) {
                this.mUploadConnection.disconnect();
                this.mUploadConnection = null;
            }
            if (this.mDownloadConnection != null) {
                this.mDownloadConnection.disconnect();
                this.mDownloadConnection = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, "BDSHttpRequestMaker cancelRequest exception");
        }
    }

    /* access modifiers changed from: package-private */
    public void logD(String str, String str2) {
        Log.d(str, str2 + " &" + Integer.toHexString(hashCode()) + ", ");
    }

    /* access modifiers changed from: package-private */
    public void logI(String str, String str2) {
        Log.i(str, str2 + " &" + Integer.toHexString(hashCode()) + ", ");
    }

    /* access modifiers changed from: package-private */
    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: r13v0, types: [java.io.BufferedInputStream] */
    /* JADX WARN: Type inference failed for: r19v0, types: [java.io.BufferedInputStream] */
    /* JADX WARN: Type inference failed for: r3v4 */
    /* JADX WARN: Type inference failed for: r19v1 */
    /* JADX WARN: Type inference failed for: r3v5 */
    /* JADX WARN: Type inference failed for: r19v2, types: [java.io.BufferedInputStream] */
    /* JADX WARN: Type inference failed for: r3v13 */
    /* JADX WARN: Type inference failed for: r3v14 */
    /* JADX WARN: Type inference failed for: r19v5, types: [java.io.BufferedInputStream] */
    /* JADX WARN: Type inference failed for: r13v7 */
    /* JADX WARN: Type inference failed for: r3v18 */
    /* JADX WARN: Type inference failed for: r19v6 */
    /* JADX WARN: Type inference failed for: r3v19 */
    /* JADX WARN: Type inference failed for: r3v20 */
    /* JADX WARN: Type inference failed for: r3v21 */
    /* JADX WARN: Type inference failed for: r3v22 */
    /* JADX WARN: Type inference failed for: r13v13 */
    /* JADX WARN: Type inference failed for: r13v14, types: [java.io.BufferedInputStream] */
    /* JADX WARN: Type inference failed for: r19v16 */
    /* JADX WARN: Type inference failed for: r19v17 */
    /* JADX WARN: Type inference failed for: r19v18 */
    /* JADX WARN: Type inference failed for: r19v19 */
    /* JADX WARN: Type inference failed for: r13v27 */
    /* JADX WARN: Type inference failed for: r19v20 */
    /* JADX WARN: Type inference failed for: r19v22 */
    /* JADX WARN: Type inference failed for: r19v23 */
    /* JADX WARN: Type inference failed for: r13v28 */
    /* JADX WARN: Type inference failed for: r13v29 */
    /* JADX WARN: Type inference failed for: r13v30 */
    /* JADX WARNING: Code restructure failed: missing block: B:100:0x0270, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:101:0x0271, code lost:
        r2 = r0;
        r8 = r8;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:102:0x0273, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:103:0x0274, code lost:
        r20 = r6;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:104:0x0276, code lost:
        r3 = r0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:105:0x0277, code lost:
        r19 = r13;
        r13 = r14;
        r8 = r8;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:106:0x027c, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:107:0x027d, code lost:
        r2 = r0;
        r8 = r8;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:118:0x029b, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:119:0x029d, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:120:0x029e, code lost:
        r2 = r0;
        r8 = null;
        r13 = 0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:121:0x02a4, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:122:0x02a5, code lost:
        r2 = r0;
        r8 = null;
        r19 = null;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:128:0x02b8, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:129:0x02b9, code lost:
        r2 = r0;
        r8 = null;
        r19 = null;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:148:0x0307, code lost:
        r13.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:151:?, code lost:
        r19.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:152:0x0310, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:153:0x0311, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:155:0x0317, code lost:
        r8.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:162:0x032e, code lost:
        com.baidu.speech.utils.LogUtil.d(com.baidu.speech.core.BDSHttpRequestMaker.TAG, "EOF Exception from http connection, trying again...");
        r9 = r9 + 1;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:163:0x033b, code lost:
        if (r13 != null) goto L_0x033d;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:164:0x033d, code lost:
        r13.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:165:0x0340, code lost:
        if (r13 != null) goto L_0x0342;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:166:0x0342, code lost:
        r13.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:167:0x0345, code lost:
        if (r19 != 0) goto L_0x0347;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:169:?, code lost:
        r19.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:170:0x034b, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:171:0x034c, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:172:0x0350, code lost:
        if (r8 != null) goto L_0x0352;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:174:?, code lost:
        r8.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:175:0x0356, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:176:0x0357, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:178:0x0364, code lost:
        com.baidu.speech.utils.LogUtil.d(com.baidu.speech.core.BDSHttpRequestMaker.TAG, "EOF Exception from http connection giving up...");
        r5.m_request_status = 2;
        r5.m_http_status = com.baidu.speech.utils.AsrError.ERROR_NETWORK_FAIL_CONNECT;
        r5.m_log = "error_msg=" + r3.getMessage();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:179:0x038d, code lost:
        if (r13 != null) goto L_0x038f;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:180:0x038f, code lost:
        r13.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:181:0x0392, code lost:
        if (r19 != 0) goto L_0x0394;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:183:?, code lost:
        r19.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:184:0x0398, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:185:0x0399, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:186:0x039d, code lost:
        if (r8 != null) goto L_0x039f;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:187:0x039f, code lost:
        r8.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:205:0x03d1, code lost:
        r14.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:208:?, code lost:
        r13.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:209:0x03da, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:210:0x03db, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:213:?, code lost:
        r8.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:214:0x03e5, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:215:0x03e6, code lost:
        r0.printStackTrace();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:21:0x0076, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:22:0x0077, code lost:
        r2 = r0;
        r8 = null;
        r13 = 0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:23:0x007c, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:24:0x007d, code lost:
        r2 = r0;
        r13 = r14;
        r8 = null;
        r19 = 0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:28:0x0090, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:29:0x0091, code lost:
        r2 = r0;
        r13 = r14;
        r8 = null;
        r19 = 0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:42:0x00ee, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:58:0x011e, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:59:0x011f, code lost:
        r3 = r0;
        r20 = r6;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:71:0x01d6, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:72:0x01d7, code lost:
        r0.printStackTrace();
        r5.m_http_status = com.baidu.speech.utils.AsrError.ERROR_NETWORK_FAIL_DATA_DOWN;
        r5.m_response_data = null;
        r5.m_request_status = 0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:97:0x026a, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:98:0x026c, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:99:0x026d, code lost:
        r2 = r0;
        r8 = r8;
        r13 = r13;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Removed duplicated region for block: B:100:0x0270 A[ExcHandler: Exception (r0v34 'e' java.lang.Exception A[CUSTOM_DECLARE]), Splitter:B:50:0x010b] */
    /* JADX WARNING: Removed duplicated region for block: B:106:0x027c A[ExcHandler: SocketTimeoutException (r0v31 'e' java.net.SocketTimeoutException A[CUSTOM_DECLARE]), Splitter:B:50:0x010b] */
    /* JADX WARNING: Removed duplicated region for block: B:119:0x029d A[ExcHandler: all (r0v26 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:15:0x0065] */
    /* JADX WARNING: Removed duplicated region for block: B:121:0x02a4 A[ExcHandler: Exception (r0v25 'e' java.lang.Exception A[CUSTOM_DECLARE]), Splitter:B:15:0x0065] */
    /* JADX WARNING: Removed duplicated region for block: B:128:0x02b8 A[ExcHandler: SocketTimeoutException (r0v21 'e' java.net.SocketTimeoutException A[CUSTOM_DECLARE]), Splitter:B:15:0x0065] */
    /* JADX WARNING: Removed duplicated region for block: B:148:0x0307  */
    /* JADX WARNING: Removed duplicated region for block: B:150:0x030c A[SYNTHETIC, Splitter:B:150:0x030c] */
    /* JADX WARNING: Removed duplicated region for block: B:155:0x0317  */
    /* JADX WARNING: Removed duplicated region for block: B:162:0x032e  */
    /* JADX WARNING: Removed duplicated region for block: B:193:0x03b6  */
    /* JADX WARNING: Removed duplicated region for block: B:195:0x03bb A[SYNTHETIC, Splitter:B:195:0x03bb] */
    /* JADX WARNING: Removed duplicated region for block: B:200:0x03c6  */
    /* JADX WARNING: Removed duplicated region for block: B:205:0x03d1  */
    /* JADX WARNING: Removed duplicated region for block: B:207:0x03d6 A[SYNTHETIC, Splitter:B:207:0x03d6] */
    /* JADX WARNING: Removed duplicated region for block: B:212:0x03e1 A[SYNTHETIC, Splitter:B:212:0x03e1] */
    /* JADX WARNING: Removed duplicated region for block: B:217:0x0364 A[SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:21:0x0076 A[Catch:{ SocketTimeoutException -> 0x0090, IOException -> 0x0084, Exception -> 0x007c, all -> 0x0076 }, ExcHandler: all (r0v46 'th' java.lang.Throwable A[CUSTOM_DECLARE, Catch:{ SocketTimeoutException -> 0x0090, IOException -> 0x0084, Exception -> 0x007c, all -> 0x0076 }]), Splitter:B:19:0x006e] */
    /* JADX WARNING: Removed duplicated region for block: B:23:0x007c A[Catch:{ SocketTimeoutException -> 0x0090, IOException -> 0x0084, Exception -> 0x007c, all -> 0x0076 }, ExcHandler: Exception (r0v45 'e' java.lang.Exception A[CUSTOM_DECLARE, Catch:{ SocketTimeoutException -> 0x0090, IOException -> 0x0084, Exception -> 0x007c, all -> 0x0076 }]), Splitter:B:19:0x006e] */
    /* JADX WARNING: Removed duplicated region for block: B:28:0x0090 A[Catch:{ SocketTimeoutException -> 0x0090, IOException -> 0x0084, Exception -> 0x007c, all -> 0x0076 }, ExcHandler: SocketTimeoutException (r0v43 'e' java.net.SocketTimeoutException A[CUSTOM_DECLARE, Catch:{ SocketTimeoutException -> 0x0090, IOException -> 0x0084, Exception -> 0x007c, all -> 0x0076 }]), Splitter:B:19:0x006e] */
    /* JADX WARNING: Removed duplicated region for block: B:97:0x026a A[ExcHandler: IOException (e java.io.IOException), Splitter:B:61:0x013f] */
    /* JADX WARNING: Removed duplicated region for block: B:98:0x026c A[ExcHandler: all (r0v35 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:50:0x010b] */
    /* JADX WARNING: Unknown variable types count: 6 */
    public BDSHTTPResponse makeRequest(String str, byte[] bArr, String[] strArr, float f, int i) {
        HttpURLConnection httpURLConnection;
        ?? r13;
        ByteArrayOutputStream byteArrayOutputStream;
        Throwable th;
        ?? r19;
        HttpURLConnection httpURLConnection2;
        ByteArrayOutputStream byteArrayOutputStream2;
        SocketTimeoutException socketTimeoutException;
        ?? r3;
        SocketTimeoutException e;
        long j;
        ?? r192;
        HttpURLConnection httpURLConnection3;
        ByteArrayOutputStream byteArrayOutputStream3;
        IOException iOException;
        HttpURLConnection httpURLConnection4;
        ByteArrayOutputStream byteArrayOutputStream4;
        IOException e2;
        ?? r193;
        HttpURLConnection httpURLConnection5;
        ByteArrayOutputStream byteArrayOutputStream5;
        Exception exc;
        Exception e3;
        Throwable th2;
        HttpURLConnection httpURLConnection6;
        ByteArrayOutputStream byteArrayOutputStream6;
        long currentTimeMillis;
        ?? bufferedInputStream;
        ByteArrayOutputStream byteArrayOutputStream7;
        byte[] bArr2 = bArr;
        String[] strArr2 = strArr;
        try {
            mHostIp = new URL(str).getHost();
        } catch (Exception e4) {
            e4.printStackTrace();
        }
        BDSHTTPResponse bDSHTTPResponse = new BDSHTTPResponse();
        long currentTimeMillis2 = System.currentTimeMillis();
        char c = 0;
        int i2 = 0;
        while (true) {
            if (Log.isLoggable(TAG, 3) || DEBUG.booleanValue()) {
                logD(TAG, "Begin request, url is " + str);
            }
            try {
                if (System.currentTimeMillis() - currentTimeMillis2 <= 500) {
                    URL url = new URL(str);
                    long currentTimeMillis3 = System.currentTimeMillis();
                    httpURLConnection = (HttpURLConnection) url.openConnection();
                    try {
                        currentTimeMillis = System.currentTimeMillis();
                        if (httpURLConnection instanceof HttpsURLConnection) {
                            try {
                                ((HttpsURLConnection) httpURLConnection).setHostnameVerifier(this.DO_NOT_VERIFY);
                            } catch (SocketTimeoutException e5) {
                            } catch (IOException e6) {
                                e = e6;
                                iOException = e;
                                j = currentTimeMillis2;
                                httpURLConnection3 = httpURLConnection;
                                byteArrayOutputStream3 = null;
                                r192 = 0;
                                iOException.printStackTrace();
                                if (i2 >= 30) {
                                }
                            } catch (Exception e7) {
                            } catch (Throwable th3) {
                            }
                        }
                        int i3 = 0;
                        while (strArr2 != null && i3 < strArr2.length - 1) {
                            httpURLConnection.setRequestProperty(strArr2[i3], strArr2[i3 + 1]);
                            i3 += 2;
                        }
                        httpURLConnection.setDoInput(true);
                        if (i != 1 || bArr2 == null) {
                            int i4 = (int) (1000.0f * f);
                            httpURLConnection.setConnectTimeout(i4);
                            httpURLConnection.setReadTimeout(i4);
                        } else {
                            httpURLConnection.setDoOutput(true);
                            httpURLConnection.setFixedLengthStreamingMode(bArr2.length);
                            httpURLConnection.setReadTimeout(10000);
                            httpURLConnection.setConnectTimeout(8000);
                            final URLConnection[] uRLConnectionArr = new URLConnection[1];
                            uRLConnectionArr[c] = httpURLConnection;
                            Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
                                /* class com.baidu.speech.core.BDSHttpRequestMaker.AnonymousClass2 */

                                @Override // java.util.concurrent.Callable
                                public Void call() throws Exception {
                                    uRLConnectionArr[0].connect();
                                    return null;
                                }
                            }).get(10, TimeUnit.SECONDS);
                            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(httpURLConnection.getOutputStream());
                            bufferedOutputStream.write(bArr2);
                            bufferedOutputStream.close();
                        }
                        bufferedInputStream = new BufferedInputStream(httpURLConnection.getInputStream());
                    } catch (SocketTimeoutException e8) {
                    } catch (IOException e9) {
                        e2 = e9;
                        j = currentTimeMillis2;
                        byteArrayOutputStream6 = null;
                        httpURLConnection6 = null;
                        httpURLConnection3 = httpURLConnection;
                        byteArrayOutputStream4 = byteArrayOutputStream6;
                        httpURLConnection4 = httpURLConnection6;
                        iOException = e2;
                        byteArrayOutputStream3 = byteArrayOutputStream4;
                        r192 = httpURLConnection4;
                        iOException.printStackTrace();
                        if (i2 >= 30) {
                        }
                    } catch (Exception e10) {
                    } catch (Throwable th4) {
                    }
                    try {
                        byteArrayOutputStream7 = new ByteArrayOutputStream();
                        try {
                            byte[] bArr3 = new byte[16384];
                            while (true) {
                                int read = bufferedInputStream.read(bArr3, 0, bArr3.length);
                                if (read == -1) {
                                    break;
                                }
                                byteArrayOutputStream7.write(bArr3, 0, read);
                            }
                            byteArrayOutputStream7.flush();
                            long currentTimeMillis4 = System.currentTimeMillis();
                            j = currentTimeMillis2;
                            LogUtil.d("End request from java: url: " + str, new String[0]);
                            LogUtil.d("http url: " + str, new String[0]);
                            bDSHTTPResponse.m_response_data = byteArrayOutputStream7.toByteArray();
                            bDSHTTPResponse.m_http_status = httpURLConnection.getResponseCode();
                            bDSHTTPResponse.m_request_status = 0;
                            bDSHTTPResponse.m_log = "connect_time=" + (currentTimeMillis - currentTimeMillis3) + "&request-response_time=" + (currentTimeMillis4 - currentTimeMillis);
                            if (Log.isLoggable(TAG, 3) || DEBUG.booleanValue()) {
                                logD(TAG, "Receive response, data: " + new String(bDSHTTPResponse.m_response_data) + " httpStatus: " + bDSHTTPResponse.m_http_status);
                            }
                            String str2 = new String(bDSHTTPResponse.m_response_data);
                            if (!str2.startsWith("license_begin")) {
                                new JSONObject(str2);
                            }
                        } catch (SocketTimeoutException e11) {
                        } catch (IOException e12) {
                        } catch (Exception e13) {
                        } catch (Throwable th5) {
                        }
                    } catch (SocketTimeoutException e14) {
                        socketTimeoutException = e14;
                        ByteArrayOutputStream byteArrayOutputStream8 = null;
                        Object obj = bufferedInputStream;
                        ByteArrayOutputStream byteArrayOutputStream9 = byteArrayOutputStream8;
                        httpURLConnection2 = httpURLConnection;
                        byteArrayOutputStream2 = byteArrayOutputStream9;
                        r19 = obj;
                        socketTimeoutException.printStackTrace();
                        bDSHTTPResponse.m_http_status = AsrError.ERROR_NETWORK_FAIL_READ_DOWN;
                        bDSHTTPResponse.m_request_status = 0;
                        if (httpURLConnection2 != null) {
                            httpURLConnection2.disconnect();
                        }
                        if (r19 != 0) {
                            try {
                                r19.close();
                            } catch (IOException e15) {
                                e15.printStackTrace();
                            }
                        }
                        if (byteArrayOutputStream2 != null) {
                            byteArrayOutputStream2.close();
                        }
                        return bDSHTTPResponse;
                    } catch (IOException e16) {
                        e2 = e16;
                        j = currentTimeMillis2;
                        byteArrayOutputStream6 = null;
                        httpURLConnection6 = bufferedInputStream;
                        httpURLConnection3 = httpURLConnection;
                        byteArrayOutputStream4 = byteArrayOutputStream6;
                        httpURLConnection4 = httpURLConnection6;
                        iOException = e2;
                        byteArrayOutputStream3 = byteArrayOutputStream4;
                        r192 = httpURLConnection4;
                        iOException.printStackTrace();
                        if (i2 >= 30) {
                        }
                    } catch (Exception e17) {
                        exc = e17;
                        ByteArrayOutputStream byteArrayOutputStream10 = null;
                        Object obj2 = bufferedInputStream;
                        ByteArrayOutputStream byteArrayOutputStream11 = byteArrayOutputStream10;
                        httpURLConnection5 = httpURLConnection;
                        byteArrayOutputStream5 = byteArrayOutputStream11;
                        r193 = obj2;
                        try {
                            exc.printStackTrace();
                            bDSHTTPResponse.m_http_status = AsrError.ERROR_NETWORK_FAIL_CONNECT;
                            bDSHTTPResponse.m_request_status = 2;
                            bDSHTTPResponse.m_log = "error_msg=" + exc.getMessage();
                            if (httpURLConnection5 != null) {
                            }
                            if (r193 != 0) {
                            }
                            if (byteArrayOutputStream5 != null) {
                            }
                            return bDSHTTPResponse;
                        } catch (Throwable th6) {
                            th = th6;
                            httpURLConnection = httpURLConnection5;
                            r13 = r193;
                            byteArrayOutputStream = byteArrayOutputStream5;
                            if (httpURLConnection != null) {
                            }
                            if (r13 != 0) {
                            }
                            if (byteArrayOutputStream != null) {
                            }
                            throw th;
                        }
                    } catch (Throwable th7) {
                        th = th7;
                        byteArrayOutputStream = null;
                        r13 = bufferedInputStream;
                        if (httpURLConnection != null) {
                        }
                        if (r13 != 0) {
                        }
                        if (byteArrayOutputStream != null) {
                        }
                        throw th;
                    }
                } else {
                    j = currentTimeMillis2;
                    r3 = null;
                    try {
                        throw new SocketTimeoutException();
                    } catch (SocketTimeoutException e18) {
                        e = e18;
                        socketTimeoutException = e;
                        ByteArrayOutputStream byteArrayOutputStream12 = r3;
                        httpURLConnection2 = byteArrayOutputStream12;
                        r19 = httpURLConnection2;
                        byteArrayOutputStream2 = byteArrayOutputStream12;
                        socketTimeoutException.printStackTrace();
                        bDSHTTPResponse.m_http_status = AsrError.ERROR_NETWORK_FAIL_READ_DOWN;
                        bDSHTTPResponse.m_request_status = 0;
                        if (httpURLConnection2 != null) {
                        }
                        if (r19 != 0) {
                        }
                        if (byteArrayOutputStream2 != null) {
                        }
                        return bDSHTTPResponse;
                    } catch (IOException e19) {
                        e2 = e19;
                        ByteArrayOutputStream byteArrayOutputStream13 = r3;
                        httpURLConnection3 = byteArrayOutputStream13;
                        httpURLConnection4 = httpURLConnection3;
                        byteArrayOutputStream4 = byteArrayOutputStream13;
                        iOException = e2;
                        byteArrayOutputStream3 = byteArrayOutputStream4;
                        r192 = httpURLConnection4;
                        iOException.printStackTrace();
                        if (i2 >= 30) {
                        }
                    } catch (Exception e20) {
                        e3 = e20;
                        exc = e3;
                        ByteArrayOutputStream byteArrayOutputStream14 = r3;
                        httpURLConnection5 = byteArrayOutputStream14;
                        r193 = httpURLConnection5;
                        byteArrayOutputStream5 = byteArrayOutputStream14;
                        exc.printStackTrace();
                        bDSHTTPResponse.m_http_status = AsrError.ERROR_NETWORK_FAIL_CONNECT;
                        bDSHTTPResponse.m_request_status = 2;
                        bDSHTTPResponse.m_log = "error_msg=" + exc.getMessage();
                        if (httpURLConnection5 != null) {
                        }
                        if (r193 != 0) {
                        }
                        if (byteArrayOutputStream5 != null) {
                        }
                        return bDSHTTPResponse;
                    } catch (Throwable th8) {
                        th2 = th8;
                        th = th2;
                        ByteArrayOutputStream byteArrayOutputStream15 = r3;
                        ByteArrayOutputStream byteArrayOutputStream16 = byteArrayOutputStream15;
                        httpURLConnection = byteArrayOutputStream16;
                        byteArrayOutputStream = byteArrayOutputStream15;
                        r13 = byteArrayOutputStream16;
                        if (httpURLConnection != null) {
                        }
                        if (r13 != 0) {
                        }
                        if (byteArrayOutputStream != null) {
                        }
                        throw th;
                    }
                }
            } catch (SocketTimeoutException e21) {
                e = e21;
                r3 = null;
                socketTimeoutException = e;
                ByteArrayOutputStream byteArrayOutputStream122 = r3;
                httpURLConnection2 = byteArrayOutputStream122;
                r19 = httpURLConnection2;
                byteArrayOutputStream2 = byteArrayOutputStream122;
                socketTimeoutException.printStackTrace();
                bDSHTTPResponse.m_http_status = AsrError.ERROR_NETWORK_FAIL_READ_DOWN;
                bDSHTTPResponse.m_request_status = 0;
                if (httpURLConnection2 != null) {
                }
                if (r19 != 0) {
                }
                if (byteArrayOutputStream2 != null) {
                }
                return bDSHTTPResponse;
            } catch (IOException e22) {
                e2 = e22;
                j = currentTimeMillis2;
                r3 = null;
                ByteArrayOutputStream byteArrayOutputStream132 = r3;
                httpURLConnection3 = byteArrayOutputStream132;
                httpURLConnection4 = httpURLConnection3;
                byteArrayOutputStream4 = byteArrayOutputStream132;
                iOException = e2;
                byteArrayOutputStream3 = byteArrayOutputStream4;
                r192 = httpURLConnection4;
                iOException.printStackTrace();
                if (i2 >= 30) {
                }
            } catch (Exception e23) {
                e3 = e23;
                r3 = null;
                exc = e3;
                ByteArrayOutputStream byteArrayOutputStream142 = r3;
                httpURLConnection5 = byteArrayOutputStream142;
                r193 = httpURLConnection5;
                byteArrayOutputStream5 = byteArrayOutputStream142;
                exc.printStackTrace();
                bDSHTTPResponse.m_http_status = AsrError.ERROR_NETWORK_FAIL_CONNECT;
                bDSHTTPResponse.m_request_status = 2;
                bDSHTTPResponse.m_log = "error_msg=" + exc.getMessage();
                if (httpURLConnection5 != null) {
                }
                if (r193 != 0) {
                }
                if (byteArrayOutputStream5 != null) {
                }
                return bDSHTTPResponse;
            } catch (Throwable th9) {
                th2 = th9;
                r3 = null;
                th = th2;
                ByteArrayOutputStream byteArrayOutputStream152 = r3;
                ByteArrayOutputStream byteArrayOutputStream162 = byteArrayOutputStream152;
                httpURLConnection = byteArrayOutputStream162;
                byteArrayOutputStream = byteArrayOutputStream152;
                r13 = byteArrayOutputStream162;
                if (httpURLConnection != null) {
                }
                if (r13 != 0) {
                }
                if (byteArrayOutputStream != null) {
                }
                throw th;
            }
            currentTimeMillis2 = j;
            bArr2 = bArr;
            strArr2 = strArr;
            c = 0;
        }
        Map<String, List<String>> headerFields = httpURLConnection.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;
                bDSHTTPResponse.m_response_headers[i5] = entry.getKey() != null ? entry.getKey() : "";
                int i7 = i6 + 1;
                bDSHTTPResponse.m_response_headers[i6] = entry.getValue().get(0) != null ? entry.getValue().get(0) : "";
                i5 = i7;
            }
        }
        if (httpURLConnection != null) {
            httpURLConnection.disconnect();
        }
        try {
            bufferedInputStream.close();
        } catch (IOException e24) {
            e24.printStackTrace();
        }
        try {
            byteArrayOutputStream7.close();
        } catch (IOException e25) {
            e25.printStackTrace();
        }
        return bDSHTTPResponse;
    }

    /* JADX WARNING: Removed duplicated region for block: B:57:0x0169  */
    /* JADX WARNING: Removed duplicated region for block: B:58:0x016c  */
    /* JADX WARNING: Removed duplicated region for block: B:62:0x0185 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 & Pdu.MANUFACTURER_DATA_PDU_TYPE;
                if (243 == i2) {
                    this.mUploadConnctionStatus = 2;
                    this.mDownloadConnectionStatus = 2;
                }
                if (Log.isLoggable(TAG, 3) || DEBUG.booleanValue()) {
                    logI(TAG, "readData dataType : " + i2 + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR + 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 = AsrError.ERROR_NETWORK_FAIL_DATA_DOWN;
                    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 + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR + 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) {
                        BDSHTTPResponse bDSHTTPResponse4 = new BDSHTTPResponse();
                        bDSHTTPResponse4.m_http_status = !this.mAgentDownload ? AsrError.ERROR_NETWORK_FAIL_AGENT_READ_DOWN : AsrError.ERROR_NETWORK_FAIL_READ_DOWN;
                        bDSHTTPResponse4.m_response_data = null;
                        bDSHTTPResponse4.m_request_status = 0;
                        this.mAgentDownload = false;
                        this.mErrorArray.add(bDSHTTPResponse4);
                        if (this.mErrorArray.size() <= 0) {
                        }
                        BDSHTTPResponse bDSHTTPResponse5 = this.mErrorArray.get(0);
                        this.mErrorArray.clear();
                        return bDSHTTPResponse5;
                    } catch (SSLException unused2) {
                        bDSHTTPResponse2 = new BDSHTTPResponse();
                        logI(TAG, "SSLException");
                        bDSHTTPResponse2.m_http_status = AsrError.ERROR_NETWORK_NOT_AVAILABLE;
                        bDSHTTPResponse2.m_response_data = null;
                        bDSHTTPResponse2.m_request_status = 0;
                        this.mErrorArray.add(bDSHTTPResponse2);
                        if (this.mErrorArray.size() <= 0) {
                        }
                        BDSHTTPResponse bDSHTTPResponse52 = this.mErrorArray.get(0);
                        this.mErrorArray.clear();
                        return bDSHTTPResponse52;
                    } catch (Exception e2) {
                        e = e2;
                        logI(TAG, "Exception");
                        e.printStackTrace();
                        bDSHTTPResponse2 = new BDSHTTPResponse();
                        bDSHTTPResponse2.m_http_status = AsrError.ERROR_NETWORK_NOT_AVAILABLE;
                        bDSHTTPResponse2.m_response_data = null;
                        bDSHTTPResponse2.m_request_status = 0;
                        this.mErrorArray.add(bDSHTTPResponse2);
                        if (this.mErrorArray.size() <= 0) {
                        }
                        BDSHTTPResponse bDSHTTPResponse522 = this.mErrorArray.get(0);
                        this.mErrorArray.clear();
                        return bDSHTTPResponse522;
                    }
                }
                bDSHTTPResponse.m_request_status = 0;
            } catch (SocketTimeoutException unused3) {
                bDSHTTPResponse = null;
                BDSHTTPResponse bDSHTTPResponse42 = new BDSHTTPResponse();
                bDSHTTPResponse42.m_http_status = !this.mAgentDownload ? AsrError.ERROR_NETWORK_FAIL_AGENT_READ_DOWN : AsrError.ERROR_NETWORK_FAIL_READ_DOWN;
                bDSHTTPResponse42.m_response_data = null;
                bDSHTTPResponse42.m_request_status = 0;
                this.mAgentDownload = false;
                this.mErrorArray.add(bDSHTTPResponse42);
                if (this.mErrorArray.size() <= 0) {
                }
                BDSHTTPResponse bDSHTTPResponse5222 = this.mErrorArray.get(0);
                this.mErrorArray.clear();
                return bDSHTTPResponse5222;
            } catch (SSLException unused4) {
                bDSHTTPResponse = null;
                bDSHTTPResponse2 = new BDSHTTPResponse();
                logI(TAG, "SSLException");
                bDSHTTPResponse2.m_http_status = AsrError.ERROR_NETWORK_NOT_AVAILABLE;
                bDSHTTPResponse2.m_response_data = null;
                bDSHTTPResponse2.m_request_status = 0;
                this.mErrorArray.add(bDSHTTPResponse2);
                if (this.mErrorArray.size() <= 0) {
                }
                BDSHTTPResponse bDSHTTPResponse52222 = this.mErrorArray.get(0);
                this.mErrorArray.clear();
                return bDSHTTPResponse52222;
            } catch (Exception e3) {
                e = e3;
                bDSHTTPResponse = null;
                logI(TAG, "Exception");
                e.printStackTrace();
                bDSHTTPResponse2 = new BDSHTTPResponse();
                bDSHTTPResponse2.m_http_status = AsrError.ERROR_NETWORK_NOT_AVAILABLE;
                bDSHTTPResponse2.m_response_data = null;
                bDSHTTPResponse2.m_request_status = 0;
                this.mErrorArray.add(bDSHTTPResponse2);
                if (this.mErrorArray.size() <= 0) {
                }
                BDSHTTPResponse bDSHTTPResponse522222 = this.mErrorArray.get(0);
                this.mErrorArray.clear();
                return bDSHTTPResponse522222;
            }
            if (this.mErrorArray.size() <= 0) {
                return bDSHTTPResponse;
            }
        }
        BDSHTTPResponse bDSHTTPResponse5222222 = this.mErrorArray.get(0);
        this.mErrorArray.clear();
        return bDSHTTPResponse5222222;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:26:0x0087, code lost:
        r6 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:27:0x0088, code lost:
        r6.printStackTrace();
        r6 = new com.baidu.speech.core.BDSHTTPResponse();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:28:0x0092, code lost:
        if (r5.mAgentUpload != false) goto L_0x0094;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:29:0x0094, code lost:
        r7 = com.baidu.speech.utils.AsrError.ERROR_NETWORK_FAIL_AGENT_READ_UP;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:30:0x0097, code lost:
        r7 = com.baidu.speech.utils.AsrError.ERROR_NETWORK_FAIL_READ_UP;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:31:0x0099, code lost:
        r6.m_http_status = r7;
        r6.m_response_data = null;
        r6.m_request_status = 0;
        r5.mErrorArray.add(r6);
        r5.mAgentUpload = false;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:33:0x00a7, code lost:
        logW(com.baidu.speech.core.BDSHttpRequestMaker.TAG, "send data EOFException");
        r6 = new com.baidu.speech.core.BDSHTTPResponse();
        r6.m_http_status = com.baidu.speech.utils.AsrError.ERROR_NETWORK_NOT_AVAILABLE;
        r6.m_response_data = null;
        r6.m_request_status = 0;
        r5.mErrorArray.add(r6);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:35:0x00c0, code lost:
        return -1;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Removed duplicated region for block: B:26:0x0087 A[ExcHandler: Exception (r6v3 'e' java.lang.Exception A[CUSTOM_DECLARE]), Splitter:B:10:0x004a] */
    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] & Pdu.MANUFACTURER_DATA_PDU_TYPE;
        if (Log.isLoggable(TAG, 3) || DEBUG.booleanValue()) {
            logI(TAG, "sendData  dataType : " + i + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR + this.mUploadConnection.getURL());
        }
        try {
            if (this.mUploadConnection == null) {
                Log.e(TAG, "Upload conncetion not exist");
                return -1;
            }
            if (this.mUploadOutputStream == null) {
                this.mUploadOutputStream = this.mUploadConnection.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:0x00ef  */
    /* JADX WARNING: Removed duplicated region for block: B:35:0x00f4  */
    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();
            }
            if (this.mDownloadConnection instanceof HttpsURLConnection) {
                ((HttpsURLConnection) this.mDownloadConnection).setHostnameVerifier(this.DO_NOT_VERIFY);
            }
            this.mDownloadConnection.setConnectTimeout(AsrError.ERROR_AUDIO_INCORRECT);
            this.mDownloadConnection.setReadTimeout(10000);
            this.mDownloadConnection.setRequestMethod("POST");
            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] & Pdu.MANUFACTURER_DATA_PDU_TYPE));
                }
            }
        } 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 : AsrError.ERROR_NETWORK_FAIL_CONNECT_DOWN;
                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 : AsrError.ERROR_NETWORK_FAIL_CONNECT_DOWN;
            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:0x0096  */
    /* JADX WARNING: Removed duplicated region for block: B:27:0x009b  */
    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();
            }
            if (this.mUploadConnection instanceof HttpsURLConnection) {
                ((HttpsURLConnection) this.mUploadConnection).setHostnameVerifier(this.DO_NOT_VERIFY);
            }
            this.mUploadConnection.setConnectTimeout(AsrError.ERROR_AUDIO_INCORRECT);
            this.mUploadConnection.setReadTimeout(10000);
            this.mUploadConnection.setRequestMethod("POST");
            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 = AsrError.ERROR_NETWORK_FAIL_CONNECT_UP;
                } 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;
    }
}