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


package com.mobile.auth.d;

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 com.mobile.auth.gatewayauth.ExceptionProcessor;
import com.nirvana.tools.core.MobileNetRequestManager;
import java.net.InetAddress;
import kotlin.UByte;

public class e {
    private static final String a = "e";
    private boolean b = false;
    private ConnectivityManager c = null;
    private ConnectivityManager.NetworkCallback d = null;
    private a e;
    private long f = 0;
    private long g = 0;

    public interface a {
        void a();

        void a(int i, String str, long j);

        void a(Network network, long j);
    }

    public static int a(String str) {
        try {
            byte[] address = InetAddress.getByName(str).getAddress();
            return (address[0] & UByte.MAX_VALUE) | ((address[3] & UByte.MAX_VALUE) << 24) | ((address[2] & UByte.MAX_VALUE) << 16) | ((address[1] & UByte.MAX_VALUE) << 8);
        } catch (Throwable th) {
            try {
                ExceptionProcessor.processException(th);
                return -1;
            } catch (Throwable th2) {
                ExceptionProcessor.processException(th2);
                return -1;
            }
        }
    }

    static /* synthetic */ long a(e eVar, long j) {
        try {
            eVar.f = j;
            return j;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return -1;
        }
    }

    static /* synthetic */ ConnectivityManager a(e eVar, ConnectivityManager connectivityManager) {
        try {
            eVar.c = connectivityManager;
            return connectivityManager;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return null;
        }
    }

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

    private void a(Context context) {
        try {
            this.f = 0;
            this.c = (ConnectivityManager) context.getApplicationContext().getSystemService("connectivity");
            this.g = System.currentTimeMillis();
            NetworkRequest.Builder builder = new NetworkRequest.Builder();
            builder.addCapability(12);
            builder.addTransportType(0);
            NetworkRequest build = builder.build();
            AnonymousClass2 r0 = new ConnectivityManager.NetworkCallback() {
                /* class com.mobile.auth.d.e.AnonymousClass2 */

                public void onAvailable(Network network) {
                    try {
                        long currentTimeMillis = System.currentTimeMillis();
                        e eVar = e.this;
                        e.a(eVar, currentTimeMillis - e.d(eVar));
                        e.a(e.this, true);
                        if (e.b(e.this) != null) {
                            e.b(e.this).a(network, e.e(e.this));
                        }
                        if (e.f(e.this) != null) {
                            try {
                                e.f(e.this).unregisterNetworkCallback(this);
                                e.a(e.this, (ConnectivityManager) null);
                            } catch (Throwable th) {
                                com.mobile.auth.a.a.a(e.a(), "switchToMobileForAboveL", th);
                            }
                        }
                    } catch (Throwable th2) {
                        ExceptionProcessor.processException(th2);
                    }
                }
            };
            this.d = r0;
            this.c.requestNetwork(build, r0);
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
        }
    }

    static /* synthetic */ boolean a(e eVar) {
        try {
            return eVar.b;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return false;
        }
    }

    static /* synthetic */ boolean a(e eVar, boolean z) {
        try {
            eVar.b = z;
            return z;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return false;
        }
    }

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

    public static String b(String str) {
        try {
            int indexOf = str.indexOf("://");
            if (indexOf > 0) {
                str = str.substring(indexOf + 3);
            }
            int indexOf2 = str.indexOf(58);
            if (indexOf2 >= 0) {
                str = str.substring(0, indexOf2);
            }
            int indexOf3 = str.indexOf(47);
            if (indexOf3 >= 0) {
                str = str.substring(0, indexOf3);
            }
            int indexOf4 = str.indexOf(63);
            return indexOf4 >= 0 ? str.substring(0, indexOf4) : str;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return null;
        }
    }

    private void b() {
        ConnectivityManager connectivityManager;
        ConnectivityManager.NetworkCallback networkCallback;
        try {
            if (Build.VERSION.SDK_INT >= 21 && (connectivityManager = this.c) != null && (networkCallback = this.d) != null) {
                try {
                    connectivityManager.unregisterNetworkCallback(networkCallback);
                } catch (Throwable th) {
                    com.mobile.auth.a.a.a(a, "unregisterNetworkCallback", th);
                }
                this.c = null;
            }
        } catch (Throwable th2) {
            ExceptionProcessor.processException(th2);
        }
    }

    private boolean b(Context context, String str) {
        boolean z;
        Throwable th;
        try {
            Class<?> cls = Class.forName("android.net.ConnectivityManager");
            this.f = 0;
            this.g = System.currentTimeMillis();
            ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
            this.c = connectivityManager;
            if (connectivityManager.getNetworkInfo(5).getState().compareTo((Enum) NetworkInfo.State.CONNECTED) != 0) {
                cls.getMethod("startUsingNetworkFeature", Integer.TYPE, String.class).invoke(this.c, 0, "enableHIPRI");
                for (int i = 0; i < 5; i++) {
                    try {
                        if (this.c.getNetworkInfo(5).getState().compareTo((Enum) NetworkInfo.State.CONNECTED) == 0) {
                            break;
                        }
                        Thread.sleep(500);
                    } catch (Throwable th2) {
                        com.mobile.auth.a.a.a(a, "switchToMobileForUnderL", th2);
                    }
                }
            }
            int a2 = a(b(str));
            boolean booleanValue = ((Boolean) cls.getMethod("requestRouteToHost", Integer.TYPE, Integer.TYPE).invoke(this.c, 5, Integer.valueOf(a2))).booleanValue();
            try {
                this.f = System.currentTimeMillis() - this.g;
                String str2 = a;
                com.mobile.auth.a.a.a(str2, "Switch network result : " + booleanValue + " (4.x) , expendTime :" + this.f);
                return booleanValue;
            } catch (Throwable th3) {
                z = booleanValue;
                th = th3;
            }
        } catch (Throwable th4) {
            th = th4;
            z = false;
            try {
                com.mobile.auth.a.a.a(a, "4.x网络切换异常", th);
                return z;
            } catch (Throwable th5) {
                ExceptionProcessor.processException(th5);
                return false;
            }
        }
    }

    static /* synthetic */ void c(e eVar) {
        try {
            eVar.b();
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
        }
    }

    static /* synthetic */ long d(e eVar) {
        try {
            return eVar.g;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return -1;
        }
    }

    static /* synthetic */ long e(e eVar) {
        try {
            return eVar.f;
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return -1;
        }
    }

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

    public void a(final int i) {
        try {
            i.a().a(new Runnable() {
                /* class com.mobile.auth.d.e.AnonymousClass1 */

                public void run() {
                    try {
                        if (i > 2500) {
                            try {
                                Thread.sleep(2500);
                            } catch (Throwable th) {
                                com.mobile.auth.a.a.a(e.a(), "timeoutCheckRunnable exception!", th);
                            }
                            if (!e.a(e.this)) {
                                if (e.b(e.this) != null) {
                                    e.b(e.this).a(MobileNetRequestManager.CODE_SWITCH_TIMEOUT, MobileNetRequestManager.MSG_SWITCH_TIMEOUT, 2500);
                                }
                                com.mobile.auth.a.a.a(e.a(), "切换网络超时(L)");
                                e.c(e.this);
                                return;
                            }
                        }
                        try {
                            int i = i;
                            if (i > 2500) {
                                i -= 2500;
                            }
                            Thread.sleep((long) i);
                        } catch (Throwable th2) {
                            com.mobile.auth.a.a.a(e.a(), "timeoutCheckRunnable exception!", th2);
                        }
                        if (e.b(e.this) == null) {
                            return;
                        }
                        if (!e.a(e.this)) {
                            e.b(e.this).a(MobileNetRequestManager.CODE_SWITCH_TIMEOUT, MobileNetRequestManager.MSG_SWITCH_TIMEOUT, 2500);
                            e.c(e.this);
                            return;
                        }
                        e.b(e.this).a();
                    } catch (Throwable th3) {
                        ExceptionProcessor.processException(th3);
                    }
                }
            });
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
        }
    }

    public void a(Context context, a aVar) {
        try {
            this.e = aVar;
            try {
                a(context);
            } catch (Throwable th) {
                com.mobile.auth.a.a.a(a, "switchToMobileForAboveL", th);
                if (this.e != null) {
                    this.e.a(MobileNetRequestManager.CODE_SWITCH_EXCEPTION, MobileNetRequestManager.MSG_SWITCH_EXCEPTION, -1);
                }
            }
        } catch (Throwable th2) {
            ExceptionProcessor.processException(th2);
        }
    }

    public boolean a(Context context, String str) {
        try {
            return b(context, str);
        } catch (Throwable th) {
            ExceptionProcessor.processException(th);
            return false;
        }
    }
}