9055彩票.apk(点击下载) / c.java


package com.umeng.commonsdk.statistics.internal;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.commonsdk.debug.UMLog;
import com.umeng.commonsdk.debug.UMRTLog;
import com.umeng.commonsdk.framework.UMEnvelopeBuild;
import com.umeng.commonsdk.statistics.AnalyticsConstants;
import com.umeng.commonsdk.statistics.SdkVersion;
import com.umeng.commonsdk.statistics.UMServerURL;
import com.umeng.commonsdk.statistics.b;
import com.umeng.commonsdk.statistics.common.DataHelper;
import com.umeng.commonsdk.statistics.common.DeviceConfig;
import com.umeng.commonsdk.statistics.common.HelperUtils;
import com.umeng.commonsdk.statistics.common.MLog;
import com.umeng.message.MsgConstant;
import com.umeng.message.util.HttpRequest;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.UnknownHostException;
import java.security.SecureRandom;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.eclipse.paho.client.mqttv3.internal.security.SSLSocketFactoryFactory;

/* compiled from: NetworkHelper */
public class c {
    private static boolean e = false;

    /* renamed from: a  reason: collision with root package name */
    private String f12387a = "10.0.0.172";

    /* renamed from: b  reason: collision with root package name */
    private int f12388b = 80;
    private Context c;
    private b d;

    public c(Context context) {
        this.c = context;
    }

    public void a(b bVar) {
        this.d = bVar;
    }

    private void a() {
        String imprintProperty = UMEnvelopeBuild.imprintProperty(this.c, "domain_p", "");
        String imprintProperty2 = UMEnvelopeBuild.imprintProperty(this.c, "domain_s", "");
        if (!TextUtils.isEmpty(imprintProperty)) {
            UMServerURL.DEFAULT_URL = DataHelper.assembleURL(imprintProperty);
        }
        if (!TextUtils.isEmpty(imprintProperty2)) {
            UMServerURL.SECONDARY_URL = DataHelper.assembleURL(imprintProperty2);
        }
        AnalyticsConstants.APPLOG_URL_LIST = new String[]{UMServerURL.DEFAULT_URL, UMServerURL.SECONDARY_URL};
    }

    private void b() {
        String imprintProperty = UMEnvelopeBuild.imprintProperty(this.c, "domain_p", "");
        String imprintProperty2 = UMEnvelopeBuild.imprintProperty(this.c, "domain_s", "");
        if (!TextUtils.isEmpty(imprintProperty)) {
            UMServerURL.DEFAULT_URL = DataHelper.assembleURL(imprintProperty);
        }
        if (!TextUtils.isEmpty(imprintProperty2)) {
            UMServerURL.SECONDARY_URL = DataHelper.assembleURL(imprintProperty2);
        }
        String imprintProperty3 = UMEnvelopeBuild.imprintProperty(this.c, "oversea_domain_p", "");
        String imprintProperty4 = UMEnvelopeBuild.imprintProperty(this.c, "oversea_domain_s", "");
        if (!TextUtils.isEmpty(imprintProperty3)) {
            UMServerURL.OVERSEA_DEFAULT_URL = DataHelper.assembleURL(imprintProperty3);
        }
        if (!TextUtils.isEmpty(imprintProperty4)) {
            UMServerURL.OVERSEA_SECONDARY_URL = DataHelper.assembleURL(imprintProperty4);
        }
        AnalyticsConstants.APPLOG_URL_LIST = new String[]{UMServerURL.OVERSEA_DEFAULT_URL, UMServerURL.OVERSEA_SECONDARY_URL};
        if (TextUtils.isEmpty(b.f12323b)) {
            return;
        }
        if (b.f12323b.startsWith("460") || b.f12323b.startsWith("461")) {
            AnalyticsConstants.APPLOG_URL_LIST = new String[]{UMServerURL.DEFAULT_URL, UMServerURL.SECONDARY_URL};
        }
    }

    public byte[] a(byte[] bArr, boolean z) {
        if (SdkVersion.SDK_TYPE == 0) {
            a();
        } else {
            UMServerURL.DEFAULT_URL = UMServerURL.OVERSEA_DEFAULT_URL;
            UMServerURL.SECONDARY_URL = UMServerURL.OVERSEA_SECONDARY_URL;
            b();
        }
        int i = 0;
        byte[] bArr2 = null;
        while (true) {
            if (i >= AnalyticsConstants.APPLOG_URL_LIST.length) {
                break;
            }
            bArr2 = a(bArr, AnalyticsConstants.APPLOG_URL_LIST[i]);
            if (bArr2 != null) {
                b bVar = this.d;
                if (bVar != null) {
                    bVar.onRequestSucceed(z);
                }
            } else {
                b bVar2 = this.d;
                if (bVar2 != null) {
                    bVar2.onRequestFailed();
                }
                i++;
            }
        }
        return bArr2;
    }

    private boolean c() {
        NetworkInfo activeNetworkInfo;
        String extraInfo;
        if (this.c.getPackageManager().checkPermission(MsgConstant.PERMISSION_ACCESS_NETWORK_STATE, this.c.getPackageName()) != 0) {
            return false;
        }
        try {
            ConnectivityManager connectivityManager = (ConnectivityManager) this.c.getSystemService("connectivity");
            if (!DeviceConfig.checkPermission(this.c, MsgConstant.PERMISSION_ACCESS_NETWORK_STATE) || connectivityManager == null || (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null || activeNetworkInfo.getType() == 1 || (extraInfo = activeNetworkInfo.getExtraInfo()) == null || (!extraInfo.equals("cmwap") && !extraInfo.equals("3gwap") && !extraInfo.equals("uniwap"))) {
                return false;
            }
            return true;
        } catch (Throwable th) {
            com.umeng.commonsdk.proguard.b.a(this.c, th);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:103:0x01ca A[SYNTHETIC, Splitter:B:103:0x01ca] */
    /* JADX WARNING: Removed duplicated region for block: B:108:0x01d6 A[SYNTHETIC, Splitter:B:108:0x01d6] */
    /* JADX WARNING: Removed duplicated region for block: B:116:0x01e5 A[SYNTHETIC, Splitter:B:116:0x01e5] */
    /* JADX WARNING: Removed duplicated region for block: B:121:0x01f1 A[SYNTHETIC, Splitter:B:121:0x01f1] */
    /* JADX WARNING: Removed duplicated region for block: B:71:0x017c A[SYNTHETIC, Splitter:B:71:0x017c] */
    /* JADX WARNING: Removed duplicated region for block: B:76:0x0188 A[SYNTHETIC, Splitter:B:76:0x0188] */
    /* JADX WARNING: Removed duplicated region for block: B:88:0x01a3 A[SYNTHETIC, Splitter:B:88:0x01a3] */
    /* JADX WARNING: Removed duplicated region for block: B:93:0x01af A[SYNTHETIC, Splitter:B:93:0x01af] */
    public byte[] a(byte[] bArr, String str) {
        Throwable th;
        HttpsURLConnection httpsURLConnection;
        OutputStream outputStream;
        boolean z;
        OutputStream outputStream2 = null;
        try {
            if (this.d != null) {
                this.d.onRequestStart();
            }
            if (c()) {
                httpsURLConnection = (HttpsURLConnection) new URL(str).openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(this.f12387a, this.f12388b)));
            } else {
                httpsURLConnection = (HttpsURLConnection) new URL(str).openConnection();
            }
            try {
                if (!e) {
                    httpsURLConnection.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
                    SSLContext instance = SSLContext.getInstance(SSLSocketFactoryFactory.DEFAULT_PROTOCOL);
                    instance.init(null, null, new SecureRandom());
                    httpsURLConnection.setSSLSocketFactory(instance.getSocketFactory());
                    e = true;
                }
                httpsURLConnection.setRequestProperty("X-Umeng-UTC", String.valueOf(System.currentTimeMillis()));
                httpsURLConnection.setRequestProperty("X-Umeng-Sdk", a.a(this.c).b());
                httpsURLConnection.setRequestProperty("Content-Type", a.a(this.c).a());
                httpsURLConnection.setRequestProperty("Msg-Type", "envelope/json");
                httpsURLConnection.setConnectTimeout(30000);
                httpsURLConnection.setReadTimeout(30000);
                httpsURLConnection.setRequestMethod("POST");
                httpsURLConnection.setDoOutput(true);
                httpsURLConnection.setDoInput(true);
                z = false;
                httpsURLConnection.setUseCaches(false);
                outputStream = httpsURLConnection.getOutputStream();
            } catch (SSLHandshakeException unused) {
                outputStream = null;
                MLog.i("发送数据时发生javax.net.sslHandshakeException异常,导致友盟后端对设备端证书验证失败。请确保设备端没有运行抓包代理类程序。详见链接 https://lark.alipay.com/yj131525/byt0wl/ufnf3i#A10200");
                UMLog uMLog = UMConfigure.umDebugLog;
                UMLog.aq("A_10201", 2, "\\|");
                if (outputStream != null) {
                    try {
                        outputStream.close();
                    } catch (Exception e2) {
                        com.umeng.commonsdk.proguard.b.a(this.c, e2);
                    }
                }
                if (httpsURLConnection != null) {
                    try {
                        httpsURLConnection.getInputStream().close();
                    } catch (IOException unused2) {
                    }
                    httpsURLConnection.disconnect();
                }
                return null;
            } catch (UnknownHostException unused3) {
                outputStream = null;
                try {
                    MLog.i("发送数据时发生java.net.UnknownHostException异常,导致友盟后端域名解析失败。请检查系统DNS服务器配置是否正确。详见链接 https://lark.alipay.com/yj131525/byt0wl/ufnf3i#A10200");
                    UMLog uMLog2 = UMConfigure.umDebugLog;
                    UMLog.aq("A_10200", 2, "\\|");
                    if (outputStream != null) {
                        try {
                            outputStream.close();
                        } catch (Exception e3) {
                            com.umeng.commonsdk.proguard.b.a(this.c, e3);
                        }
                    }
                    if (httpsURLConnection != null) {
                        try {
                            httpsURLConnection.getInputStream().close();
                        } catch (IOException unused4) {
                        }
                        httpsURLConnection.disconnect();
                    }
                    return null;
                } catch (Throwable th2) {
                    th = th2;
                    outputStream2 = outputStream;
                    if (outputStream2 != null) {
                        try {
                            outputStream2.close();
                        } catch (Exception e4) {
                            com.umeng.commonsdk.proguard.b.a(this.c, e4);
                        }
                    }
                    if (httpsURLConnection != null) {
                        try {
                            httpsURLConnection.getInputStream().close();
                        } catch (IOException unused5) {
                        }
                        httpsURLConnection.disconnect();
                    }
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                if (outputStream2 != null) {
                }
                if (httpsURLConnection != null) {
                }
                throw th;
            }
            try {
                outputStream.write(bArr);
                outputStream.flush();
                httpsURLConnection.connect();
                if (this.d != null) {
                    this.d.onRequestEnd();
                }
                int responseCode = httpsURLConnection.getResponseCode();
                String headerField = httpsURLConnection.getHeaderField("Content-Type");
                if (!TextUtils.isEmpty(headerField) && headerField.equalsIgnoreCase(HttpRequest.CONTENT_TYPE_THRIFT)) {
                    z = true;
                }
                if (AnalyticsConstants.UM_DEBUG) {
                    MLog.i("status code : " + responseCode + "; isThrifit:" + z);
                }
                if (responseCode != 200 || !z) {
                    if (outputStream != null) {
                        try {
                            outputStream.close();
                        } catch (Exception e5) {
                            com.umeng.commonsdk.proguard.b.a(this.c, e5);
                        }
                    }
                    if (httpsURLConnection != null) {
                        try {
                            httpsURLConnection.getInputStream().close();
                        } catch (IOException unused6) {
                        }
                        httpsURLConnection.disconnect();
                    }
                    return null;
                }
                MLog.i("Send message to server. status code is: " + responseCode);
                UMRTLog.i(UMRTLog.RTLOG_TAG, "Send message to server. status code is: " + responseCode + "; url = " + str);
                InputStream inputStream = httpsURLConnection.getInputStream();
                try {
                    byte[] readStreamToByteArray = HelperUtils.readStreamToByteArray(inputStream);
                    if (outputStream != null) {
                        try {
                            outputStream.close();
                        } catch (Exception e6) {
                            com.umeng.commonsdk.proguard.b.a(this.c, e6);
                        }
                    }
                    if (httpsURLConnection != null) {
                        try {
                            httpsURLConnection.getInputStream().close();
                        } catch (IOException unused7) {
                        }
                        httpsURLConnection.disconnect();
                    }
                    return readStreamToByteArray;
                } finally {
                    HelperUtils.safeClose(inputStream);
                }
            } catch (SSLHandshakeException unused8) {
                MLog.i("发送数据时发生javax.net.sslHandshakeException异常,导致友盟后端对设备端证书验证失败。请确保设备端没有运行抓包代理类程序。详见链接 https://lark.alipay.com/yj131525/byt0wl/ufnf3i#A10200");
                UMLog uMLog3 = UMConfigure.umDebugLog;
                UMLog.aq("A_10201", 2, "\\|");
                if (outputStream != null) {
                }
                if (httpsURLConnection != null) {
                }
                return null;
            } catch (UnknownHostException unused9) {
                MLog.i("发送数据时发生java.net.UnknownHostException异常,导致友盟后端域名解析失败。请检查系统DNS服务器配置是否正确。详见链接 https://lark.alipay.com/yj131525/byt0wl/ufnf3i#A10200");
                UMLog uMLog22 = UMConfigure.umDebugLog;
                UMLog.aq("A_10200", 2, "\\|");
                if (outputStream != null) {
                }
                if (httpsURLConnection != null) {
                }
                return null;
            } catch (Throwable unused10) {
                if (outputStream != null) {
                }
                if (httpsURLConnection != null) {
                }
                return null;
            }
        } catch (SSLHandshakeException unused11) {
            httpsURLConnection = null;
            outputStream = null;
            MLog.i("发送数据时发生javax.net.sslHandshakeException异常,导致友盟后端对设备端证书验证失败。请确保设备端没有运行抓包代理类程序。详见链接 https://lark.alipay.com/yj131525/byt0wl/ufnf3i#A10200");
            UMLog uMLog32 = UMConfigure.umDebugLog;
            UMLog.aq("A_10201", 2, "\\|");
            if (outputStream != null) {
            }
            if (httpsURLConnection != null) {
            }
            return null;
        } catch (UnknownHostException unused12) {
            httpsURLConnection = null;
            outputStream = null;
            MLog.i("发送数据时发生java.net.UnknownHostException异常,导致友盟后端域名解析失败。请检查系统DNS服务器配置是否正确。详见链接 https://lark.alipay.com/yj131525/byt0wl/ufnf3i#A10200");
            UMLog uMLog222 = UMConfigure.umDebugLog;
            UMLog.aq("A_10200", 2, "\\|");
            if (outputStream != null) {
            }
            if (httpsURLConnection != null) {
            }
            return null;
        } catch (Throwable th4) {
            th = th4;
            httpsURLConnection = null;
            if (outputStream2 != null) {
            }
            if (httpsURLConnection != null) {
            }
            throw th;
        }
    }
}