和通讯录 v3.9.6版本的 MD5 值为:669178e2ee1b2311daf378bd20c6bbe1

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


package com.huawei.tep.component.net.http;

import android.content.Context;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.text.TextUtils;
import java.net.InetSocketAddress;
import java.net.Proxy;

class ProxyManager {
    private static final long INTERVAL = 1000;
    private static Context context;
    private static boolean needProxy;
    private static String hostUrl = "10.0.0.172";
    private static int hostPort = 80;
    private static long lastTime = -1;

    ProxyManager() {
    }

    public static void setContext(Context context2) {
        context = context2;
    }

    public static synchronized Proxy getHttpProxy() {
        Proxy proxy;
        synchronized (ProxyManager.class) {
            proxy = isNeedProxy() ? new Proxy(Proxy.Type.HTTP, new InetSocketAddress(hostUrl, hostPort)) : null;
        }
        return proxy;
    }

    public static boolean isNeedProxy() {
        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis - lastTime > INTERVAL) {
            lastTime = currentTimeMillis;
            needProxy = innerIsNeedProxy();
        }
        return needProxy;
    }

    private static boolean innerIsNeedProxy() {
        NetworkInfo activeNetworkInfo;
        Cursor query;
        if (context != null && (activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo()) != null) {
            String typeName = activeNetworkInfo.getTypeName();
            if (typeName.equalsIgnoreCase("WIFI")) {
                return false;
            }
            if (typeName.equalsIgnoreCase("MOBILE") && (query = context.getContentResolver().query(Uri.parse("content://telephony/carriers/preferapn"), null, null, null, null)) != null && query.moveToFirst()) {
                String string = query.getString(9);
                String string2 = query.getString(10);
                query.close();
                if (!TextUtils.isEmpty(string) && !TextUtils.isEmpty(string2)) {
                    hostUrl = string;
                    try {
                        hostPort = Integer.parseInt(string2);
                        return true;
                    } catch (Exception e) {
                        return false;
                    }
                }
            }
            return false;
        }
        return false;
    }
}