翰林优商.apk(点击下载) / b.java


package com.mobile.auth.z;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.os.Build;
import android.text.TextUtils;
import com.mobile.auth.gatewayauth.ExceptionProcessor;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class b {
    private static b g;
    private Network a;
    private ConnectivityManager.NetworkCallback b;
    private ConnectivityManager c;
    private ExecutorService d;
    private List<a> e;
    private Timer f;

    public interface a {
        void a(boolean z, Network network);
    }

    private b() {
        this.a = null;
        this.b = null;
        this.c = null;
        this.d = null;
        this.e = null;
        this.f = null;
        this.e = new ArrayList();
        this.d = Executors.newSingleThreadExecutor();
    }

    static /* synthetic */ ConnectivityManager.NetworkCallback a(b bVar) {
        try {
            return bVar.b;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return null;
        }
    }

    static /* synthetic */ Network a(b bVar, Network network) {
        try {
            bVar.a = network;
            return network;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return null;
        }
    }

    public static b a() {
        try {
            if (g == null) {
                synchronized (b.class) {
                    if (g == null) {
                        g = new b();
                    }
                }
            }
            return g;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return null;
        }
    }

    private synchronized void a(Context context, a aVar) {
        try {
            Network network = this.a;
            if (network != null) {
                aVar.a(true, network);
                return;
            }
            a(aVar);
            if (this.b == null || this.e.size() < 2) {
                try {
                    this.c = (ConnectivityManager) context.getSystemService("connectivity");
                    NetworkRequest.Builder builder = new NetworkRequest.Builder();
                    builder.addTransportType(0);
                    builder.addCapability(12);
                    NetworkRequest build = builder.build();
                    this.b = new ConnectivityManager.NetworkCallback() {
                        /* class com.mobile.auth.z.b.AnonymousClass3 */

                        public void onAvailable(Network network) {
                            try {
                                super.onAvailable(network);
                                e.a("Network onAvailable");
                                if (b.a(b.this) != null) {
                                    b.a(b.this, network);
                                    b.a(b.this, true, network);
                                    try {
                                        NetworkInfo networkInfo = b.c(b.this).getNetworkInfo(b.b(b.this));
                                        String extraInfo = networkInfo.getExtraInfo();
                                        e.a("APN:" + networkInfo.toString());
                                        if (!TextUtils.isEmpty(extraInfo)) {
                                            f.d(extraInfo);
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            } catch (Throwable th) {
                                ExceptionProcessor.processException(th);
                            }
                        }

                        public void onLost(Network network) {
                            try {
                                super.onLost(network);
                                e.a("Network onLost");
                                b.this.b();
                            } catch (Throwable th) {
                                ExceptionProcessor.processException(th);
                            }
                        }

                        public void onUnavailable() {
                            try {
                                super.onUnavailable();
                                e.a("Network onUnavailable");
                                b.this.b();
                                b.a(b.this, false, (Network) null);
                            } catch (Throwable th) {
                                ExceptionProcessor.processException(th);
                            }
                        }
                    };
                    int i = 3000;
                    if (f.f() < 3000) {
                        i = 2000;
                    }
                    if (Build.VERSION.SDK_INT >= 26) {
                        this.c.requestNetwork(build, this.b, i);
                        return;
                    }
                    Timer timer = new Timer();
                    this.f = timer;
                    timer.schedule(new TimerTask() {
                        /* class com.mobile.auth.z.b.AnonymousClass4 */

                        public void run() {
                            try {
                                b.a(b.this, false, (Network) null);
                            } catch (Throwable th) {
                                ExceptionProcessor.processException(th);
                            }
                        }
                    }, (long) i);
                    this.c.requestNetwork(build, this.b);
                } catch (Exception e2) {
                    e2.printStackTrace();
                    a(false, (Network) null);
                }
            }
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
        }
    }

    private synchronized void a(a aVar) {
        try {
            this.e.add(aVar);
        } catch (Exception e2) {
            try {
                e2.printStackTrace();
            } catch (Throwable th) {
                ExceptionProcessor.processException(th);
            }
        }
    }

    static /* synthetic */ void a(b bVar, boolean z, Network network) {
        try {
            bVar.a(z, network);
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
        }
    }

    private synchronized void a(boolean z, Network network) {
        try {
            Timer timer = this.f;
            if (timer != null) {
                timer.cancel();
                this.f = null;
            }
            for (a aVar : this.e) {
                aVar.a(z, network);
            }
            this.e.clear();
        } catch (Exception e2) {
            try {
                e2.printStackTrace();
            } catch (Throwable th) {
                ExceptionProcessor.processException(th);
            }
        }
    }

    private boolean a(Context context, String str) {
        try {
            ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
            this.c = connectivityManager;
            if (connectivityManager == null) {
                return false;
            }
            NetworkInfo.State state = connectivityManager.getNetworkInfo(5).getState();
            if (state.compareTo((Enum) NetworkInfo.State.CONNECTED) != 0) {
                if (state.compareTo((Enum) NetworkInfo.State.CONNECTING) != 0) {
                    Method method = ConnectivityManager.class.getMethod("startUsingNetworkFeature", Integer.TYPE, String.class);
                    method.setAccessible(true);
                    int intValue = ((Integer) method.invoke(this.c, 0, "enableHIPRI")).intValue();
                    if (-1 == intValue) {
                        return false;
                    }
                    if (intValue == 0) {
                        return true;
                    }
                    String b2 = g.b(str);
                    if (!TextUtils.isEmpty(b2)) {
                        str = b2;
                    }
                    int c2 = g.c(str);
                    if (-1 == c2) {
                        return false;
                    }
                    for (int i = 0; i < 3; i++) {
                        try {
                            if (this.c.getNetworkInfo(5).getState().compareTo((Enum) NetworkInfo.State.CONNECTED) == 0) {
                                break;
                            }
                            Thread.sleep(1000);
                        } catch (InterruptedException unused) {
                        }
                    }
                    Method method2 = ConnectivityManager.class.getMethod("requestRouteToHost", Integer.TYPE, Integer.TYPE);
                    method2.setAccessible(true);
                    boolean booleanValue = ((Boolean) method2.invoke(this.c, 5, Integer.valueOf(c2))).booleanValue();
                    this.c.getNetworkInfo(5).getState();
                    return booleanValue;
                }
            }
            return true;
        } catch (Exception unused2) {
            return false;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return false;
        }
    }

    static /* synthetic */ boolean a(b bVar, Context context, String str) {
        try {
            return bVar.a(context, str);
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return false;
        }
    }

    static /* synthetic */ Network b(b bVar) {
        try {
            return bVar.a;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return null;
        }
    }

    static /* synthetic */ ConnectivityManager c(b bVar) {
        try {
            return bVar.c;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return null;
        }
    }

    public void a(final Context context, final String str, final a aVar) {
        try {
            if (Build.VERSION.SDK_INT >= 21) {
                a(context, aVar);
            } else {
                this.d.submit(new Runnable() {
                    /* class com.mobile.auth.z.b.AnonymousClass2 */

                    public void run() {
                        try {
                            boolean a2 = b.a(b.this, context, str);
                            a aVar = aVar;
                            if (aVar != null) {
                                aVar.a(a2, null);
                            }
                        } catch (Throwable th) {
                            ExceptionProcessor.processException(th);
                        }
                    }
                });
            }
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
        }
    }

    public void a(Network network, final String str) {
        try {
            this.d.submit(new Runnable() {
                /* class com.mobile.auth.z.b.AnonymousClass1 */

                public void run() {
                    try {
                        InetAddress[] allByName = InetAddress.getAllByName(str);
                        if (allByName != null && allByName.length > 0) {
                            for (int i = 0; i < allByName.length; i++) {
                                e.a("opencloud.wostore.cn:" + allByName[i].getHostAddress());
                            }
                        }
                    } catch (Exception e) {
                        try {
                            e.printStackTrace();
                        } catch (Throwable th) {
                            ExceptionProcessor.processException(th);
                        }
                    }
                }
            });
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
        }
    }

    public synchronized void b() {
        ConnectivityManager connectivityManager;
        ConnectivityManager.NetworkCallback networkCallback;
        try {
            e.b("releaseNetwork");
            Timer timer = this.f;
            if (timer != null) {
                timer.cancel();
                this.f = null;
            }
            if (!(Build.VERSION.SDK_INT < 21 || (connectivityManager = this.c) == null || (networkCallback = this.b) == null)) {
                connectivityManager.unregisterNetworkCallback(networkCallback);
            }
            this.c = null;
            this.b = null;
            this.a = null;
            this.e.clear();
        } catch (Exception e2) {
            try {
                e2.printStackTrace();
            } catch (Throwable th) {
                ExceptionProcessor.processException(th);
            }
        }
    }
}