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


package com.huawei.updatesdk.a.b.c;

import android.os.AsyncTask;
import android.text.TextUtils;
import com.huawei.updatesdk.a.a.b.b;
import com.huawei.updatesdk.a.a.d.g;
import com.huawei.updatesdk.a.b.c.c.a;
import com.huawei.updatesdk.a.b.c.c.c;
import com.huawei.updatesdk.a.b.c.c.d;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.util.concurrent.Executor;
import org.apache.http.conn.ConnectTimeoutException;
import org.json.JSONObject;

public class b extends AsyncTask<c, Void, d> {
    protected c a = null;
    private d b = null;
    private a c = null;
    private com.huawei.updatesdk.a.a.b.b d = null;
    private int e = 0;

    public b(c cVar, a aVar) {
        this.a = cVar;
        this.c = aVar;
    }

    private d a(String str, d dVar) {
        try {
            dVar.fromJson(new JSONObject(str));
            dVar.b(0);
        } catch (Exception e2) {
            com.huawei.updatesdk.a.a.c.a.a.a.a("StoreTask", "parse json error", e2);
        }
        return dVar;
    }

    private void a(d dVar, int i, d.a aVar, Throwable th) {
        if (dVar != null) {
            dVar.b(i);
            dVar.a(aVar);
            dVar.a(th.toString());
        }
    }

    private void a(d dVar, Throwable th, String str) {
        d.a aVar;
        int i = 1;
        if (th instanceof ConnectException) {
            aVar = d.a.CONNECT_EXCEPTION;
        } else if ((th instanceof SocketTimeoutException) || (th instanceof ConnectTimeoutException)) {
            aVar = d.a.CONNECT_EXCEPTION;
            i = 2;
        } else if (th instanceof IllegalArgumentException) {
            aVar = d.a.PARAM_ERROR;
            i = 5;
        } else if (th instanceof IllegalAccessException) {
            aVar = d.a.UNKNOWN_EXCEPTION;
        } else if (th instanceof ArrayIndexOutOfBoundsException) {
            aVar = d.a.NO_PROGUARD;
            i = 6;
        } else if ((th instanceof InterruptedException) || (th instanceof InterruptedIOException)) {
            a(dVar, 0, d.a.NORMAL, th);
            com.huawei.updatesdk.a.a.a.a("StoreTask", "UpdateSDK task is canceled");
            a(str, th);
        } else if (th instanceof IOException) {
            aVar = d.a.IO_EXCEPTION;
        } else {
            if (dVar != null) {
                dVar.a(th.toString());
            }
            a(str, th);
        }
        a(dVar, i, aVar, th);
        a(str, th);
    }

    private void a(String str, Throwable th) {
        StringBuilder sb = new StringBuilder("invoke store error, exceptionType:");
        sb.append(th.getClass().getName());
        sb.append(", url:");
        sb.append(str);
        sb.append(", method:");
        sb.append(this.a.b());
        sb.append(", retryTimes:" + this.e);
        String sb2 = sb.toString();
        com.huawei.updatesdk.a.a.c.a.a.a.a("StoreTask", sb2, th);
        com.huawei.updatesdk.a.a.a.a("StoreTask", "UpdateSDK call store error: " + sb2);
    }

    private boolean a(String str) {
        return TextUtils.isEmpty(str) || !g.d(str);
    }

    /* JADX WARNING: Removed duplicated region for block: B:14:0x003f  */
    /* JADX WARNING: Removed duplicated region for block: B:15:0x0047  */
    private void b(d dVar) {
        d.a aVar;
        StringBuilder sb;
        Throwable e2;
        if (!isCancelled() && this.c != null) {
            if (dVar == null) {
                com.huawei.updatesdk.a.a.c.a.a.a.b("StoreTask", "notifyResult, response is null");
                try {
                    dVar = a.a(this.a.b());
                } catch (InstantiationException e3) {
                    e2 = e3;
                    sb = new StringBuilder("notifyResult, create response error, method:");
                } catch (IllegalAccessException e4) {
                    e2 = e4;
                    sb = new StringBuilder("notifyResult, create response error, method:");
                }
                if (dVar != null) {
                    dVar = new d();
                    aVar = d.a.PARAM_ERROR;
                } else {
                    aVar = d.a.UNKNOWN_EXCEPTION;
                }
                dVar.a(aVar);
                dVar.b(1);
            }
            this.c.b(this.a, dVar);
        }
        return;
        sb.append(this.a.b());
        com.huawei.updatesdk.a.a.c.a.a.a.a("StoreTask", sb.toString(), e2);
        if (dVar != null) {
        }
        dVar.a(aVar);
        dVar.b(1);
        this.c.b(this.a, dVar);
    }

    private void b(String str) {
        com.huawei.updatesdk.a.a.a.a("StoreTask", TextUtils.isEmpty(str) ? "UpdateSDK response error, resData == null" : "UpdateSDK response error, resData is not json string");
    }

    private boolean c(d dVar) {
        if (isCancelled()) {
            return false;
        }
        if (dVar.d() != 1 && dVar.d() != 2) {
            return false;
        }
        int i = this.e;
        this.e = i + 1;
        if (i >= 3) {
            com.huawei.updatesdk.a.a.c.a.a.a.a("StoreTask", "retry completed total times = " + this.e + ",response.responseCode = " + dVar.d());
            return false;
        }
        com.huawei.updatesdk.a.a.c.a.a.a.a("StoreTask", "retry times = " + this.e + ",response.responseCode = " + dVar.d());
        return true;
    }

    private String d() {
        String a2 = com.huawei.updatesdk.b.g.a.a();
        return TextUtils.isEmpty(a2) ? "Android/1.0" : a2;
    }

    private void e() {
        b(this.b);
    }

    /* access modifiers changed from: protected */
    /* JADX WARNING: Removed duplicated region for block: B:22:0x00f5  */
    /* JADX WARNING: Removed duplicated region for block: B:24:? A[RETURN, SYNTHETIC] */
    public d a() {
        d dVar;
        String str;
        Throwable th;
        d dVar2 = null;
        try {
            dVar = a.a(this.a.b());
            try {
                if (!com.huawei.updatesdk.a.a.d.i.a.d(com.huawei.updatesdk.a.b.a.a.c().a())) {
                    dVar.b(3);
                    dVar.a(d.a.NO_NETWORK);
                } else {
                    String a2 = this.a.a();
                    String d2 = this.a.d();
                    com.huawei.updatesdk.a.a.c.a.a.a.a("StoreTask", "callStore, method:" + this.a.b() + ", url:" + d2 + ", body:" + a2);
                    com.huawei.updatesdk.a.a.b.b bVar = new com.huawei.updatesdk.a.a.b.b();
                    this.d = bVar;
                    b.a a3 = bVar.a(d2, a2, "UTF-8", d(), com.huawei.updatesdk.a.b.a.a.c().a());
                    String b2 = a3.b();
                    dVar.a(a3.a());
                    com.huawei.updatesdk.a.a.a.b("StoreTask", "UpdateSDK call store responsecode: " + dVar.b());
                    if (a3.a() / 100 == 5) {
                        dVar.b(0);
                        return dVar;
                    } else if (a(b2)) {
                        dVar.b(1);
                        dVar.a(d.a.JSON_ERROR);
                        b(b2);
                    } else {
                        dVar = a(b2, dVar);
                        com.huawei.updatesdk.a.a.c.a.a.a.a("StoreTask", "callStore response, method:" + this.a.b() + ", url:" + d2 + ", body:" + a2 + ", Receive Json msg:" + dVar.toJson());
                    }
                }
            } catch (Throwable th2) {
                th = th2;
                str = null;
                dVar2 = dVar;
                a(dVar2, th, str);
                dVar = dVar2;
                if (dVar != null) {
                }
            }
        } catch (Throwable th3) {
            th = th3;
            str = null;
            a(dVar2, th, str);
            dVar = dVar2;
            if (dVar != null) {
            }
        }
        if (dVar != null) {
            return dVar;
        }
        d dVar3 = new d();
        dVar3.b(5);
        dVar3.a(d.a.PARAM_ERROR);
        return dVar3;
    }

    /* access modifiers changed from: protected */
    /* renamed from: a */
    public d doInBackground(c... cVarArr) {
        com.huawei.updatesdk.a.a.c.a.a.a.a("StoreTask", "doInBackground, method:" + this.a.b());
        com.huawei.updatesdk.b.g.b.a(this);
        d c2 = c();
        a aVar = this.c;
        if (aVar != null) {
            aVar.a(this.a, c2);
        }
        return c2;
    }

    /* access modifiers changed from: protected */
    /* renamed from: a */
    public void onPostExecute(d dVar) {
        com.huawei.updatesdk.a.a.c.a.a.a.a("StoreTask", "onPostExecute, method:" + this.a.b());
        com.huawei.updatesdk.b.g.b.a().remove(this);
        e();
    }

    public final void a(Executor executor) {
        executeOnExecutor(executor, this.a);
    }

    public void b() {
        com.huawei.updatesdk.a.a.b.b bVar = this.d;
        if (bVar != null) {
            bVar.a();
            this.d = null;
        }
    }

    public final d c() {
        d dVar = null;
        do {
            if (this.e > 0 && dVar != null) {
                com.huawei.updatesdk.a.a.c.a.a.a.a("StoreTask", "call store error! responseCode:" + dVar.d() + ", retryTimes:" + this.e);
            }
            dVar = a();
        } while (c(dVar));
        this.b = dVar;
        return dVar;
    }
}