换机精灵 v2.5.4版本的 MD5 值为:79a45ef9a3e238691e836db31e5f23f0

以下内容为反编译后的 fv.java 源代码,内容仅作参考


package tmsdkobf;

import android.os.Looper;
import android.text.TextUtils;
import android.util.Pair;
import com.tencent.connect.common.Constants;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ProtocolException;
import java.net.Proxy;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.zip.InflaterInputStream;
import org.apache.http.HttpHeaders;
import org.apache.http.client.ClientProtocolException;
import tmsdk.common.ErrorCode;
import tmsdk.common.TMSDKContext;
import tmsdk.common.exception.NetWorkException;
import tmsdk.common.exception.NetworkOnMainThreadException;
import tmsdk.common.exception.WifiApproveException;
import tmsdk.common.utils.l;

public final class fv {
    private static volatile String mz;
    private byte[] mPostData;
    private String mUrl;
    private String mb;
    private int mc;
    private HttpURLConnection mf;
    private boolean mq;
    private boolean mr;
    private static volatile boolean ms = false;
    private static volatile String mt = null;
    private static volatile boolean mu = false;
    private static volatile boolean mv = false;
    private static volatile long mw = 0;
    private static volatile long mx = 0;
    private static Object my = new Object();
    private static ArrayList mA = new ArrayList();
    private String me = Constants.HTTP_GET;
    private int mg = -1;
    private Hashtable mh = new Hashtable(0);
    private boolean mi = false;
    private boolean mj = true;
    private byte mk = 0;
    private byte ml = 0;
    private byte mm = 0;
    private int mn = 30000;
    private int mo = 30000;
    private boolean mp = true;

    public class a implements l.a {
        private a() {
        }

        @Override
        public void b(boolean z, boolean z2) {
            if (fv.mt != null && fv.mt.equals(tmsdk.common.utils.l.getSSID()) && fv.mu) {
                if (z2) {
                    boolean unused = fv.ms = true;
                } else {
                    boolean unused2 = fv.ms = z;
                }
                boolean unused3 = fv.mv = z2;
                boolean unused4 = fv.mu = false;
            }
        }
    }

    private fv(String str) {
        this.mUrl = str;
        bR();
    }

    private void a(String str, aj ajVar) {
        try {
            getHostAddress();
            if (aj.ct != ajVar) {
                if (aj.cw == ajVar) {
                    Proxy proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(tmsdk.common.utils.f.eK(), tmsdk.common.utils.f.eL()));
                    long currentTimeMillis = System.currentTimeMillis();
                    this.mf = (HttpURLConnection) new URL(str).openConnection(proxy);
                    tmsdk.common.utils.d.d("HttpConnection", "initConnection() proxy openTimeMillis: " + (System.currentTimeMillis() - currentTimeMillis));
                    this.mi = true;
                    return;
                }
                if (this.mp && aj.cv == ajVar && "com.tencent.qqpimsecure".equals(TMSDKContext.getApplicaionContext().getPackageName())) {
                    String ssid = tmsdk.common.utils.l.getSSID();
                    if (mt == null || !mt.equals(ssid) || (System.currentTimeMillis() - mw > 5000 && !mu)) {
                        ms = false;
                        mu = true;
                        mt = ssid;
                        tmsdk.common.utils.l.a(new a());
                    } else if (ms && !mu) {
                        mu = true;
                        tmsdk.common.utils.l.a(new a());
                    }
                    mw = System.currentTimeMillis();
                }
                long currentTimeMillis2 = System.currentTimeMillis();
                this.mf = (HttpURLConnection) new URL(str).openConnection();
                tmsdk.common.utils.d.d("HttpConnection", "initConnection() openTimeMillis: " + (System.currentTimeMillis() - currentTimeMillis2));
                this.mi = false;
                this.mf.setReadTimeout(this.mo);
                this.mf.setConnectTimeout(this.mn);
            }
        } catch (IOException e) {
            throw new NetWorkException(-1056, "IOException : " + e.getMessage());
        } catch (IllegalArgumentException e2) {
            throw new NetWorkException(-1057, "IllegalArgumentException : " + e2.getMessage());
        } catch (SecurityException e3) {
            throw new NetWorkException(-1058, "SecurityException: " + e3.getMessage());
        } catch (UnsupportedOperationException e4) {
            throw new NetWorkException(-1059, "UnsupportedOperationException: " + e4.getMessage());
        } catch (WifiApproveException e5) {
        }
    }

    private void a(String str, boolean z, String str2, int i) {
        try {
            getHostAddress();
            if (z) {
                if (str2 == null) {
                    str2 = "10.0.0.172";
                }
                if (i < 0) {
                    i = 80;
                }
                this.mf = (HttpURLConnection) new URL(str).openConnection(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(str2, i)));
                this.mi = true;
            } else {
                this.mf = (HttpURLConnection) new URL(str).openConnection();
                this.mi = false;
            }
            this.mf.setReadTimeout(30000);
            this.mf.setConnectTimeout(this.mn);
        } catch (IOException e) {
            throw new NetWorkException(-1056, "IOException : " + e.getMessage());
        } catch (IllegalArgumentException e2) {
            throw new NetWorkException(-1057, "IllegalArgumentException : " + e2.getMessage());
        } catch (SecurityException e3) {
            throw new NetWorkException(-1058, "SecurityException: " + e3.getMessage());
        } catch (UnsupportedOperationException e4) {
            throw new NetWorkException(-1059, "UnsupportedOperationException: " + e4.getMessage());
        }
    }

    public static fv b(String str, boolean z) {
        bR();
        if (!tmsdk.common.utils.f.eM() && Thread.currentThread().getId() == Looper.getMainLooper().getThread().getId()) {
            throw new NetworkOnMainThreadException();
        }
        if (str == null || str.length() == 0) {
            throw new NetWorkException(ErrorCode.ERR_OPEN_CONNECTION, "url is null!");
        }
        fv fvVar = new fv(str);
        fvVar.mq = false;
        fvVar.mp = z;
        aj eH = tmsdk.common.utils.f.eH();
        if (aj.ct == eH) {
            throw new NetWorkException(-1052, "no connecition!");
        }
        fvVar.a(fvVar.mUrl, eH);
        return fvVar;
    }

    private byte[] b(InputStream inputStream) {
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
        byte[] bArr = new byte[2048];
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        while (true) {
            try {
                try {
                    int read = inputStream.read(bArr);
                    if (read == -1) {
                        break;
                    }
                    byteArrayOutputStream.write(bArr, 0, read);
                } catch (IOException e) {
                    throw new NetWorkException(-56, "get Bytes from inputStream when read buffer: " + e.getMessage());
                }
            } catch (Throwable th) {
                try {
                    bufferedInputStream.close();
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                try {
                    byteArrayOutputStream.close();
                    throw th;
                } catch (Exception e3) {
                    e3.printStackTrace();
                    throw th;
                }
            }
        }
        byte[] byteArray = byteArrayOutputStream.toByteArray();
        try {
            bufferedInputStream.close();
        } catch (Exception e4) {
            e4.printStackTrace();
        }
        try {
            byteArrayOutputStream.close();
        } catch (Exception e5) {
            e5.printStackTrace();
        }
        return byteArray;
    }

    public static void bR() {
        fz fzVar = new fz("wup");
        mx = fzVar.getLong("dnc", 0L);
        mz = fzVar.getString("cn_t_a", "");
        if (TextUtils.isEmpty(mz)) {
            return;
        }
        for (String str : mz.split("\\|")) {
            if (!TextUtils.isEmpty(str)) {
                String[] split = str.split(",");
                try {
                    synchronized (mA) {
                        if (mA.size() <= 4) {
                            mA.add(new Pair(Integer.valueOf(split[0]), Long.valueOf(split[1])));
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static boolean bS() {
        tmsdk.common.utils.d.e("HttpConnection", " couldNotConnect()");
        synchronized (my) {
            long currentTimeMillis = System.currentTimeMillis();
            long j = mx - currentTimeMillis;
            tmsdk.common.utils.d.e("HttpConnection", " couldNotConnect() diff: " + j);
            boolean z = j > 5184000;
            boolean z2 = mx - currentTimeMillis >= 0;
            if (z || !z2) {
                tmsdk.common.utils.d.e("HttpConnection", " couldNotConnect() false");
                return false;
            }
            tmsdk.common.utils.d.e("HttpConnection", " couldNotConnect() true");
            return true;
        }
    }

    private int bU() {
        close();
        if (this.mq) {
            a(this.mUrl, this.mr, this.mb, this.mc);
        } else {
            if (tmsdk.common.utils.f.eH().value() == 0) {
                throw new NetWorkException(-1052, "no connecition!");
            }
            a(this.mUrl, tmsdk.common.utils.f.eH());
        }
        setRequestMethod(this.me);
        if (Constants.HTTP_POST.equalsIgnoreCase(this.me) && this.mPostData != null) {
            setPostData(this.mPostData);
        }
        a(this.mh);
        return bT();
    }

    private void bW() {
        if (aj.cv != tmsdk.common.utils.f.eH()) {
            return;
        }
        long currentTimeMillis = System.currentTimeMillis();
        while (mu) {
            if (System.currentTimeMillis() - currentTimeMillis > 5000) {
                if (System.currentTimeMillis() - currentTimeMillis < 10000) {
                    break;
                } else {
                    currentTimeMillis = System.currentTimeMillis();
                }
            }
        }
        if (ms && !mu && !mv) {
            throw new NetWorkException(-1063, "wifi need approve!");
        }
        if (mu) {
            ms = true;
        }
    }

    private boolean isConnected() {
        return this.mg == 200 || this.mg == 206;
    }

    private String[] split(String str) {
        String[] strArr = new String[2];
        int indexOf = str.indexOf("://");
        if (-1 != indexOf) {
            str = str.substring(indexOf + 3);
        }
        int indexOf2 = str.indexOf("/");
        if (-1 != indexOf2) {
            strArr[0] = str.substring(0, indexOf2);
            strArr[1] = str.substring(indexOf2);
        } else {
            strArr[0] = str;
            strArr[1] = "";
        }
        return strArr;
    }

    public int a(boolean z, AtomicReference atomicReference) {
        if (this.mf == null || !isConnected()) {
            return ErrorCode.ERR_RESPONSE;
        }
        try {
            atomicReference.set(b(z ? new InflaterInputStream(this.mf.getInputStream()) : this.mf.getInputStream()));
            return 0;
        } catch (NetWorkException e) {
            throw new NetWorkException(e.getErrCode() + ErrorCode.ERR_RESPONSE, "get response exception : " + e.getMessage());
        } catch (Exception e2) {
            throw new NetWorkException(-4002, "get response exception : " + e2.getMessage());
        }
    }

    public void a(Hashtable hashtable) {
        if (hashtable == null || hashtable.size() == 0 || this.mf == null) {
            return;
        }
        for (Map.Entry entry : hashtable.entrySet()) {
            this.mf.setRequestProperty((String) entry.getKey(), (String) entry.getValue());
        }
    }

    public int bT() {
        int i;
        int i2;
        boolean bS = bS();
        tmsdk.common.utils.d.e("sendRequest", " sendRequest() couldNotConnect:" + bS);
        if (bS) {
            throw new NetWorkException(ErrorCode.ERR_OPEN_CONNECTION, "sendRequest() is forbidden couldNotConnect");
        }
        if (this.mp && "com.tencent.qqpimsecure".equals(TMSDKContext.getApplicaionContext().getPackageName())) {
            bW();
        }
        try {
            if (tmsdk.common.utils.h.fb() < 8) {
                System.setProperty("http.keepAlive", "false");
            }
            this.mf.setUseCaches(false);
            this.mf.setRequestProperty(HttpHeaders.PRAGMA, "no-cache");
            this.mf.setRequestProperty(HttpHeaders.CACHE_CONTROL, "no-cache");
            this.mf.setInstanceFollowRedirects(false);
            i = this.me;
            try {
                if (Constants.HTTP_GET.equalsIgnoreCase(i)) {
                    i2 = ErrorCode.ERR_GET;
                    this.mf.setRequestMethod(Constants.HTTP_GET);
                } else {
                    i2 = ErrorCode.ERR_POST;
                    this.mf.setRequestMethod(Constants.HTTP_POST);
                    if (!this.mh.containsKey(HttpHeaders.ACCEPT)) {
                        this.mf.setRequestProperty(HttpHeaders.ACCEPT, "*/*");
                        this.mf.setRequestProperty(HttpHeaders.ACCEPT_CHARSET, "utf-8");
                    }
                    this.mf.setDoOutput(true);
                    this.mf.setDoInput(true);
                    if (this.mPostData != null) {
                        if (!this.mh.containsKey("Content-Type")) {
                            this.mf.setRequestProperty("Content-Type", "application/octet-stream");
                        }
                        this.mf.setRequestProperty("Content-length", "" + this.mPostData.length);
                        long currentTimeMillis = System.currentTimeMillis();
                        OutputStream outputStream = this.mf.getOutputStream();
                        long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis;
                        tmsdk.common.utils.d.d("HttpConnection", "sendRequest() connectTimeMillis: " + currentTimeMillis2);
                        if (currentTimeMillis2 > 0 && currentTimeMillis2 < 60000 && mA.size() <= 4) {
                            synchronized (mA) {
                                mA.add(new Pair(Integer.valueOf(fm.lU), Long.valueOf(currentTimeMillis2)));
                                if (4 == mA.size()) {
                                    StringBuilder sb = new StringBuilder();
                                    for (int i3 = 0; i3 < mA.size(); i3++) {
                                        Pair pair = (Pair) mA.get(i3);
                                        if (pair != null) {
                                            sb.append(pair.first);
                                            sb.append(",");
                                            sb.append(pair.second);
                                            if (mA.size() - 1 != i3) {
                                                sb.append("|");
                                            }
                                        }
                                    }
                                    mz = sb.toString();
                                    new fz("wup").a("cn_t_a", mz, true);
                                    tmsdk.common.utils.d.d("HttpConnection", "sendRequest() mConnectTimeMillisAll: " + mz);
                                }
                            }
                        }
                        outputStream.write(this.mPostData);
                        outputStream.flush();
                        outputStream.close();
                    }
                }
                this.mg = this.mf.getResponseCode();
                tmsdk.common.utils.d.e("HttpConnection", "HttpUrlConn.getResponseCode : " + this.mg);
                if (this.mg >= 301 && this.mg <= 305) {
                    byte b2 = this.mk;
                    this.mk = (byte) (b2 + 1);
                    if (b2 < 3) {
                        this.mUrl = bV();
                        return bU();
                    }
                } else if (this.mg == 200) {
                    String contentType = getContentType();
                    if (this.mi && contentType != null && contentType.toLowerCase().indexOf("vnd.wap.wml") != -1) {
                        byte b3 = this.ml;
                        this.ml = (byte) (b3 + 1);
                        if (b3 < 1) {
                            return bU();
                        }
                    }
                }
                if (this.mg == 206 || this.mg == 200) {
                    return this.mg;
                }
                byte b4 = this.mm;
                this.mm = (byte) (b4 + 1);
                if (b4 >= 2) {
                    throw new NetWorkException(this.mg + i2, "response code is unnormal: " + this.mg + " SDK Version:" + tmsdk.common.utils.h.fb());
                }
                if (i2 == -1 && "true".equals(System.getProperty("http.keepAlive"))) {
                    System.setProperty("http.keepAlive", "false");
                }
                return bU();
            } catch (NetWorkException e) {
                e = e;
                byte b5 = this.mm;
                this.mm = (byte) (b5 + 1);
                if (b5 < 2) {
                    return bU();
                }
                throw new NetWorkException(i - 56, "sendRequest NetWorkException: " + e.getMessage());
            } catch (Exception e2) {
                e = e2;
                byte b6 = this.mm;
                this.mm = (byte) (b6 + 1);
                if (b6 < 2) {
                    return bU();
                }
                throw new NetWorkException(i, "sendRequest " + e.getClass().getName() + " : " + e.getMessage());
            } catch (IllegalAccessError e3) {
                e = e3;
                byte b7 = this.mm;
                this.mm = (byte) (b7 + 1);
                if (b7 < 2) {
                    return bU();
                }
                throw new NetWorkException(i - 60, "sendRequest IllegalAccessError: " + e.getMessage());
            } catch (IllegalStateException e4) {
                e = e4;
                byte b8 = this.mm;
                this.mm = (byte) (b8 + 1);
                if (b8 < 2) {
                    return bU();
                }
                throw new NetWorkException(i - 61, "sendRequest IllegalStateException: " + e.getMessage());
            } catch (ProtocolException e5) {
                e = e5;
                byte b9 = this.mm;
                this.mm = (byte) (b9 + 1);
                if (b9 < 2) {
                    return bU();
                }
                throw new NetWorkException(i - 51, "sendRequest ProtocolException: " + e.getMessage());
            } catch (SocketException e6) {
                e = e6;
                byte b10 = this.mm;
                this.mm = (byte) (b10 + 1);
                if (b10 < 2) {
                    return bU();
                }
                throw new NetWorkException(i - 54, "sendRequest SocketException: " + e.getMessage());
            } catch (SocketTimeoutException e7) {
                e = e7;
                byte b11 = this.mm;
                this.mm = (byte) (b11 + 1);
                if (b11 >= 2) {
                    throw new NetWorkException(i - 55, "sendRequest" + e.getMessage());
                }
                this.mn = 60000;
                this.mo = 60000;
                return bU();
            } catch (UnknownHostException e8) {
                e = e8;
                byte b12 = this.mm;
                this.mm = (byte) (b12 + 1);
                if (b12 < 2) {
                    getHostAddress();
                    return bU();
                }
                if (this.mj) {
                    this.mj = false;
                    close();
                    if (this.mi) {
                        a(this.mUrl, aj.cx);
                    } else if (aj.cv == tmsdk.common.utils.f.eH()) {
                        String eK = tmsdk.common.utils.f.eK();
                        if (eK == null || eK.length() <= 0 || tmsdk.common.utils.f.eL() <= 0) {
                            throw new NetWorkException(i - 62, "sendRequest UnknownHostException: " + e.getMessage() + " networktype:" + tmsdk.common.utils.f.eH());
                        }
                        a(this.mUrl, aj.cw);
                    }
                    if (this.mf != null) {
                        setRequestMethod(this.me);
                        if (Constants.HTTP_POST.equalsIgnoreCase(this.me) && this.mPostData != null) {
                            setPostData(this.mPostData);
                        }
                        a(this.mh);
                        return bT();
                    }
                }
                throw new NetWorkException(i - 62, "sendRequest UnknownHostException: " + e.getMessage() + " networktype:" + tmsdk.common.utils.f.eH());
            } catch (ClientProtocolException e9) {
                e = e9;
                byte b13 = this.mm;
                this.mm = (byte) (b13 + 1);
                if (b13 < 2) {
                    return bU();
                }
                throw new NetWorkException(i - 51, "sendRequest ClientProtocolException: " + e.getMessage());
            }
        } catch (IllegalAccessError e10) {
            e = e10;
            i = 0;
        } catch (IllegalStateException e11) {
            e = e11;
            i = 0;
        } catch (ProtocolException e12) {
            e = e12;
            i = 0;
        } catch (SocketException e13) {
            e = e13;
            i = 0;
        } catch (SocketTimeoutException e14) {
            e = e14;
            i = 0;
        } catch (UnknownHostException e15) {
            e = e15;
            i = 0;
        } catch (ClientProtocolException e16) {
            e = e16;
            i = 0;
        } catch (NetWorkException e17) {
            e = e17;
            i = 0;
        } catch (Exception e18) {
            e = e18;
            i = 0;
        }
    }

    public String bV() {
        try {
            return this.mf.getHeaderField(HttpHeaders.LOCATION);
        } catch (Exception e) {
            throw new NetWorkException(-56, "get redirect url: " + e.getMessage());
        }
    }

    public void close() {
        if (this.mf != null) {
            this.mf.disconnect();
            this.mf = null;
        }
    }

    public String getContentType() {
        try {
            return this.mf.getHeaderField("Content-Type");
        } catch (Exception e) {
            throw new NetWorkException(-56, "get content type: " + e.getMessage());
        }
    }

    public String getHostAddress() {
        if (this.mUrl == null) {
            return "";
        }
        String host = this.mf != null ? this.mf.getURL().getHost() : split(this.mUrl)[0];
        if ((host == null || host.length() == 0) && this.mf == null) {
            host = split(this.mUrl)[0];
        }
        try {
            InetAddress byName = InetAddress.getByName(host);
            if (byName != null) {
                return byName.getHostAddress();
            }
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (UnknownHostException e2) {
            e2.printStackTrace();
        }
        return "";
    }

    public void setPostData(byte[] bArr) {
        this.mPostData = bArr;
    }

    public void setRequestMethod(String str) {
        this.me = str;
        if (Constants.HTTP_GET.equalsIgnoreCase(str)) {
            this.me = Constants.HTTP_GET;
        } else if (Constants.HTTP_POST.equalsIgnoreCase(str)) {
            this.me = Constants.HTTP_POST;
        }
    }
}