大漢易經書院.apk(点击下载) / fw.java


package com.xiaomi.push;

import android.content.Context;
import android.os.SystemClock;
import android.text.TextUtils;
import com.huawei.hms.support.api.entity.core.JosStatusCodes;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.xiaomi.channel.commonutils.logger.b;
import com.xiaomi.mipush.sdk.Constants;
import com.xiaomi.push.service.XMPushService;
import com.xiaomi.push.service.m;
import java.io.IOException;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Iterator;

public abstract class fw extends fp {
    protected Exception a = null;

    /* renamed from: a  reason: collision with other field name */
    protected Socket f7041a;
    protected XMPushService b;
    private int c;

    /* renamed from: c  reason: collision with other field name */
    String f7042c = null;
    private String d;
    protected volatile long e = 0;
    protected volatile long f = 0;
    protected volatile long g = 0;
    private long h = 0;

    public fw(XMPushService xMPushService, fq fqVar) {
        super(xMPushService, fqVar);
        this.b = xMPushService;
    }

    private void a(fq fqVar) {
        a(fqVar.c(), fqVar.m9369a());
    }

    /* JADX WARNING: Removed duplicated region for block: B:37:0x0187  */
    /* JADX WARNING: Removed duplicated region for block: B:38:0x0189  */
    /* JADX WARNING: Removed duplicated region for block: B:41:0x01a4  */
    /* JADX WARNING: Removed duplicated region for block: B:44:0x01c6  */
    /* JADX WARNING: Removed duplicated region for block: B:53:0x0213  */
    /* JADX WARNING: Removed duplicated region for block: B:54:0x0215  */
    /* JADX WARNING: Removed duplicated region for block: B:57:0x022e  */
    /* JADX WARNING: Removed duplicated region for block: B:58:0x0246  */
    /* JADX WARNING: Removed duplicated region for block: B:65:0x0298  */
    /* JADX WARNING: Removed duplicated region for block: B:66:0x029a  */
    /* JADX WARNING: Removed duplicated region for block: B:69:0x02b3  */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x02c8  */
    /* JADX WARNING: Removed duplicated region for block: B:73:0x02d5  */
    /* JADX WARNING: Removed duplicated region for block: B:75:0x02d9  */
    /* JADX WARNING: Removed duplicated region for block: B:80:0x02f2  */
    /* JADX WARNING: Removed duplicated region for block: B:87:0x032a  */
    /* JADX WARNING: Removed duplicated region for block: B:93:0x02d6 A[EDGE_INSN: B:93:0x02d6->B:74:0x02d6 ?: BREAK  , SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:94:0x02d6 A[EDGE_INSN: B:94:0x02d6->B:74:0x02d6 ?: BREAK  , SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:98:0x0255 A[SYNTHETIC] */
    private void a(String str, int i) {
        StringBuilder sb;
        long j;
        int i2;
        String str2;
        boolean z;
        String next;
        int i3;
        cr crVar;
        String str3;
        String str4;
        Throwable th;
        String str5;
        String str6;
        Iterator<String> it;
        String str7;
        Exception e2;
        String str8;
        Throwable th2;
        this.a = null;
        ArrayList<String> arrayList = new ArrayList<>();
        int intValue = b.a("get bucket for host : " + str).intValue();
        cr a2 = a(str);
        b.a(Integer.valueOf(intValue));
        if (a2 != null) {
            arrayList = a2.a(true);
        }
        cr d2 = cv.a().d(str);
        if (d2 != null) {
            Iterator<String> it2 = d2.a(true).iterator();
            while (it2.hasNext()) {
                String next2 = it2.next();
                if (arrayList.indexOf(next2) == -1) {
                    arrayList.add(next2);
                }
            }
        }
        if (arrayList.isEmpty()) {
            arrayList.add(str);
        }
        long j2 = 0;
        this.g = 0;
        long elapsedRealtime = SystemClock.elapsedRealtime();
        String a3 = bj.m9153a((Context) this.b);
        StringBuilder sb2 = new StringBuilder();
        Iterator<String> it3 = arrayList.iterator();
        String str9 = "";
        int i4 = 0;
        while (true) {
            if (!it3.hasNext()) {
                sb = sb2;
                j = j2;
                i2 = i4;
                str2 = str9;
                break;
            }
            next = it3.next();
            long currentTimeMillis = System.currentTimeMillis();
            this.f7022a++;
            i3 = i4 + 1;
            try {
                b.m9051a("begin to connect to " + next);
                this.f7041a = m9374a();
                this.f7041a.connect(ct.m9207a(next, i), JosStatusCodes.RTN_CODE_COMMON_ERROR);
                b.m9051a("tcp connected");
                this.f7041a.setTcpNoDelay(true);
                this.d = next;
                m9375a();
                this.f7023a = System.currentTimeMillis() - currentTimeMillis;
                this.f7032b = a3;
                if (a2 == null) {
                    sb = sb2;
                    j = 0;
                    break;
                }
                it = it3;
                sb = sb2;
                str8 = a3;
                j = 0;
                crVar = a2;
                try {
                    a2.b(next, this.f7023a, 0);
                    break;
                } catch (Exception e3) {
                    e2 = e3;
                    str4 = str9;
                    str3 = str8;
                    try {
                        this.a = e2;
                        b.d("SMACK: Could not connect to:" + next);
                        sb.append("SMACK: Could not connect to ");
                        sb.append(next);
                        sb.append(" port:");
                        sb.append(i);
                        sb.append(" err:");
                        sb.append(this.a.getClass().getSimpleName());
                        sb.append("\n");
                        if (!TextUtils.isEmpty(str4)) {
                        }
                        hd.a(next, this.a);
                        if (crVar == null) {
                        }
                        if (TextUtils.equals(str7, bj.m9153a((Context) this.b))) {
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        b.d("SMACK: Could not connect to:" + next);
                        sb.append("SMACK: Could not connect to ");
                        sb.append(next);
                        sb.append(" port:");
                        sb.append(i);
                        sb.append(" err:");
                        sb.append(this.a.getClass().getSimpleName());
                        sb.append("\n");
                        if (!TextUtils.isEmpty(str4)) {
                            str5 = next;
                        } else {
                            str5 = str4 + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + next;
                        }
                        hd.a(next, this.a);
                        if (crVar == null) {
                            str6 = str3;
                            crVar.b(next, System.currentTimeMillis() - currentTimeMillis, 0, this.a);
                        } else {
                            str6 = str3;
                        }
                        if (TextUtils.equals(str6, bj.m9153a((Context) this.b))) {
                            str2 = str5;
                            i2 = i3;
                            z = false;
                            cv.a().m9217c();
                            int elapsedRealtime2 = (int) (SystemClock.elapsedRealtime() - elapsedRealtime);
                            if (!z) {
                            }
                        } else {
                            throw th;
                        }
                    }
                } catch (Throwable th4) {
                    th2 = th4;
                    try {
                        this.a = new Exception("abnormal exception", th2);
                        b.a(th2);
                        b.d("SMACK: Could not connect to:" + next);
                        sb.append("SMACK: Could not connect to ");
                        sb.append(next);
                        sb.append(" port:");
                        sb.append(i);
                        sb.append(" err:");
                        sb.append(this.a.getClass().getSimpleName());
                        sb.append("\n");
                        if (!TextUtils.isEmpty(str9)) {
                        }
                        hd.a(next, this.a);
                        if (crVar != null) {
                        }
                        if (TextUtils.equals(str8, bj.m9153a((Context) this.b))) {
                        }
                    } catch (Throwable th5) {
                        th = th5;
                        str4 = str9;
                        str3 = str8;
                        b.d("SMACK: Could not connect to:" + next);
                        sb.append("SMACK: Could not connect to ");
                        sb.append(next);
                        sb.append(" port:");
                        sb.append(i);
                        sb.append(" err:");
                        sb.append(this.a.getClass().getSimpleName());
                        sb.append("\n");
                        if (!TextUtils.isEmpty(str4)) {
                        }
                        hd.a(next, this.a);
                        if (crVar == null) {
                        }
                        if (TextUtils.equals(str6, bj.m9153a((Context) this.b))) {
                        }
                    }
                }
            } catch (Exception e4) {
                e2 = e4;
                it = it3;
                sb = sb2;
                crVar = a2;
                j = 0;
                str4 = str9;
                str3 = a3;
                this.a = e2;
                b.d("SMACK: Could not connect to:" + next);
                sb.append("SMACK: Could not connect to ");
                sb.append(next);
                sb.append(" port:");
                sb.append(i);
                sb.append(" err:");
                sb.append(this.a.getClass().getSimpleName());
                sb.append("\n");
                if (!TextUtils.isEmpty(str4)) {
                    str2 = next;
                } else {
                    str2 = str4 + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + next;
                }
                hd.a(next, this.a);
                if (crVar == null) {
                    str7 = str3;
                    crVar.b(next, System.currentTimeMillis() - currentTimeMillis, 0, this.a);
                } else {
                    str7 = str3;
                }
                if (TextUtils.equals(str7, bj.m9153a((Context) this.b))) {
                    i2 = i3;
                    z = false;
                    cv.a().m9217c();
                    int elapsedRealtime22 = (int) (SystemClock.elapsedRealtime() - elapsedRealtime);
                    if (!z) {
                    }
                } else {
                    str9 = str2;
                    sb2 = sb;
                    a3 = str7;
                    i4 = i3;
                    it3 = it;
                    j2 = j;
                    a2 = crVar;
                }
            } catch (Throwable th6) {
                th2 = th6;
                it = it3;
                sb = sb2;
                str8 = a3;
                crVar = a2;
                j = 0;
                this.a = new Exception("abnormal exception", th2);
                b.a(th2);
                b.d("SMACK: Could not connect to:" + next);
                sb.append("SMACK: Could not connect to ");
                sb.append(next);
                sb.append(" port:");
                sb.append(i);
                sb.append(" err:");
                sb.append(this.a.getClass().getSimpleName());
                sb.append("\n");
                if (!TextUtils.isEmpty(str9)) {
                    str2 = next;
                } else {
                    str2 = str9 + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + next;
                }
                hd.a(next, this.a);
                if (crVar != null) {
                    crVar.b(next, System.currentTimeMillis() - currentTimeMillis, 0, this.a);
                }
                if (TextUtils.equals(str8, bj.m9153a((Context) this.b))) {
                    i2 = i3;
                    z = false;
                    cv.a().m9217c();
                    int elapsedRealtime222 = (int) (SystemClock.elapsedRealtime() - elapsedRealtime);
                    if (!z) {
                    }
                } else {
                    str7 = str8;
                    str9 = str2;
                    sb2 = sb;
                    a3 = str7;
                    i4 = i3;
                    it3 = it;
                    j2 = j;
                    a2 = crVar;
                }
            }
            cv.a().m9217c();
            int elapsedRealtime2222 = (int) (SystemClock.elapsedRealtime() - elapsedRealtime);
            if (!z) {
                if (this.h == j || SystemClock.elapsedRealtime() - this.h > 480000) {
                    this.h = SystemClock.elapsedRealtime();
                    hd.a(0, fa.BATCH_TCP_CONN_FAIL.a(), elapsedRealtime2222, str2, bj.c(this.b.getApplicationContext()) ? 1 : 0);
                }
                throw new ga(sb.toString());
            }
            hd.a(0, fa.BATCH_TCP_CONN_SUCCESS.a(), elapsedRealtime2222, str2, i2);
            return;
            str9 = str2;
            sb2 = sb;
            a3 = str7;
            i4 = i3;
            it3 = it;
            j2 = j;
            a2 = crVar;
        }
        this.g = SystemClock.elapsedRealtime();
        b.m9051a("connected to " + next + " in " + this.f7023a);
        str2 = str9;
        i2 = i3;
        z = true;
        cv.a().m9217c();
        int elapsedRealtime22222 = (int) (SystemClock.elapsedRealtime() - elapsedRealtime);
        if (!z) {
        }
    }

    /* access modifiers changed from: package-private */
    @Override // com.xiaomi.push.fp
    public cr a(String str) {
        cr a2 = cv.a().a(str, false);
        if (!a2.b()) {
            gs.a(new fz(this, str));
        }
        return a2;
    }

    @Override // com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp
    public String a() {
        return this.d;
    }

    @Override // com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp
    /* renamed from: a  reason: collision with other method in class */
    public Socket m9374a() {
        return new Socket();
    }

    /* access modifiers changed from: protected */
    @Override // com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp, com.xiaomi.push.fp
    /* renamed from: a  reason: collision with other method in class */
    public synchronized void m9375a() {
    }

    /* access modifiers changed from: protected */
    public synchronized void a(int i, Exception exc) {
        if (b() != 2) {
            a(2, i, exc);
            this.f7027a = "";
            try {
                this.f7041a.close();
            } catch (Throwable unused) {
            }
            this.e = 0;
            this.f = 0;
        }
    }

    /* access modifiers changed from: protected */
    public void a(Exception exc) {
        if (SystemClock.elapsedRealtime() - this.g < Constants.ASSEMBLE_PUSH_NETWORK_INTERVAL) {
            if (bj.b(this.b)) {
                int i = this.c + 1;
                this.c = i;
                if (i >= 2) {
                    String a2 = a();
                    b.m9051a("max short conn time reached, sink down current host:" + a2);
                    a(a2, 0, exc);
                } else {
                    return;
                }
            } else {
                return;
            }
        }
        this.c = 0;
    }

    /* access modifiers changed from: protected */
    public void a(String str, long j, Exception exc) {
        cr a2 = cv.a().a(fq.a(), false);
        if (a2 != null) {
            a2.b(str, j, 0, exc);
            cv.a().m9217c();
        }
    }

    /* access modifiers changed from: protected */
    public abstract void a(boolean z);

    @Override // com.xiaomi.push.fp
    public void a(fe[] feVarArr) {
        throw new ga("Don't support send Blob");
    }

    @Override // com.xiaomi.push.fp
    public void b(int i, Exception exc) {
        a(i, exc);
        if ((exc != null || i == 18) && this.g != 0) {
            a(exc);
        }
    }

    @Override // com.xiaomi.push.fp
    public void b(boolean z) {
        long elapsedRealtime = SystemClock.elapsedRealtime();
        long currentTimeMillis = System.currentTimeMillis();
        a(z);
        m.a(this.b).m9726c();
        if (!z) {
            this.b.a(new fx(this, 13, elapsedRealtime, currentTimeMillis), 10000);
        }
    }

    @Override // com.xiaomi.push.fp, com.xiaomi.push.fp
    public String c() {
        return this.f7027a;
    }

    public void c(int i, Exception exc) {
        this.b.a(new fy(this, 2, i, exc));
    }

    public synchronized void e() {
        try {
            if (!c()) {
                if (!b()) {
                    a(0, 0, (Exception) null);
                    a(this.f7024a);
                    return;
                }
            }
            b.m9051a("WARNING: current xmpp has connected");
        } catch (IOException e2) {
            throw new ga(e2);
        }
    }

    public void f() {
        this.e = SystemClock.elapsedRealtime();
    }

    public void g() {
        this.f = SystemClock.elapsedRealtime();
    }
}