大xiang v2.8.2版本的 MD5 值为:15b284c26af8fa068f351168eb25f2f1

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


package com.win.first;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.webkit.WebSettings;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
public class Utils {
    public static String getPackageVersionName(Context context) {
        try {
            return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
        } catch (Exception unused) {
            return new String();
        }
    }

    public static boolean isNetConnection(Context context) {
        if (context != null) {
            try {
                NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
                if (activeNetworkInfo == null) {
                    return false;
                }
                boolean isConnected = activeNetworkInfo.isConnected();
                if (activeNetworkInfo != null && isConnected) {
                    if (activeNetworkInfo.getState() == NetworkInfo.State.CONNECTED) {
                        return true;
                    }
                }
            } catch (Exception unused) {
            }
        }
        return false;
    }

    public static boolean isOnline() {
        try {
            new URL("https://www.baidu.com").openStream();
            return true;
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return false;
        } catch (IOException e2) {
            e2.printStackTrace();
            return false;
        }
    }

    public static boolean pingIpAddress() {
        try {
            return Runtime.getRuntime().exec("ping -c 1 -w 5 www.baidu.com").waitFor() == 0;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        } catch (InterruptedException e2) {
            e2.printStackTrace();
            return false;
        }
    }

    public static int compareVersion(String str, String str2) throws Exception {
        if (str == null || str2 == null) {
            throw new Exception("compareVersion error:illegal params.");
        }
        String[] split = str.split("\\.");
        String[] split2 = str2.split("\\.");
        int min = Math.min(split.length, split2.length);
        int i = 0;
        for (int i2 = 0; i2 < min; i2++) {
            i = split[i2].length() - split2[i2].length();
            if (i != 0 || (i = split[i2].compareTo(split2[i2])) != 0) {
                break;
            }
        }
        return i != 0 ? i : split.length - split2.length;
    }

    public static String getUserAgent(Context context) {
        String property;
        if (Build.VERSION.SDK_INT >= 17) {
            try {
                property = WebSettings.getDefaultUserAgent(context);
            } catch (Exception unused) {
                property = System.getProperty("http.agent");
            }
        } else {
            property = System.getProperty("http.agent");
        }
        StringBuffer stringBuffer = new StringBuffer();
        int length = property.length();
        for (int i = 0; i < length; i++) {
            char charAt = property.charAt(i);
            if (charAt <= 31 || charAt >= 127) {
                stringBuffer.append(String.format("\\u%04x", Integer.valueOf(charAt)));
            } else {
                stringBuffer.append(charAt);
            }
        }
        return stringBuffer.toString();
    }

    public static String getNetWorkClass(Context context) {
        try {
            int networkType = ((TelephonyManager) context.getSystemService("phone")).getNetworkType();
            if (networkType != 20) {
                switch (networkType) {
                    case 1:
                    case 2:
                    case 4:
                    case 7:
                    case 11:
                        return Constants.NETWORK_CLASS_2_G;
                    case 3:
                    case 5:
                    case 6:
                    case 8:
                    case 9:
                    case 10:
                    case 12:
                    case 14:
                    case 15:
                        return Constants.NETWORK_CLASS_3_G;
                    case 13:
                        return Constants.NETWORK_CLASS_4_G;
                    default:
                        return Constants.NETWORK_WIFI;
                }
            }
            return Constants.NETWORK_CLASS_5_G;
        } catch (Exception unused) {
            return "unknown";
        }
    }
}