智慧城市 v1.2.1版本的 MD5 值为:d4aeacb5153a2710d0b6882be5dd2b15

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


package io.rong.imlib.navigation;

import android.content.Context;
import android.text.TextUtils;
import cn.rongcloud.rtc.engine.RCEvent;
import com.bumptech.glide.load.Key;
import io.rong.common.LibStorageUtils;
import io.rong.common.RLog;
import io.rong.common.SystemUtils;
import io.rong.common.fwlog.FwLog;
import io.rong.common.utils.SSLUtils;
import io.rong.imlib.CMPStrategy;
import io.rong.imlib.HttpDnsManager;
import io.rong.imlib.common.NetUtils;
import io.rong.imlib.filetransfer.download.BaseRequest;
import io.rong.imlib.filetransfer.upload.FilePlatformInfo;
import io.rong.imlib.navigation.NetDetection;
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
public class NavigationClient {
    private static final String NAVIGATION_2_HTTPS_URL = "https://nav2-cn.ronghub.com/navi.json";
    private static final String NAVIGATION_2_HTTP_URL = "http://nav2-cn.ronghub.com/navi.json";
    private static final String NAVIGATION_HTTPS_URL = "https://nav.cn.ronghub.com/navi.json";
    private static final String NAVIGATION_HTTP_IP_URL = "http://%s/navi.json";
    private static final String NAVIGATION_HTTP_URL = "http://nav.cn.ronghub.com/navi.json";
    private static final String NAVI_IN_TOKEN_SPLIT_SYMBOL = "@";
    private static final String NAVI_SPLIT_SYMBOL = ";";
    private static final String SEP1 = ";";
    private static final String TAG = "NavigationClient";
    private final String NAVI_SUFFIX;
    private Context context;
    private volatile boolean enableHttps;
    private ExecutorService executor;
    private AtomicBoolean fetching;
    private String latestTokenNaviEncodeStr;
    private List<String> latestTokenNaviList;
    private String naviString;
    private NaviUpdateListener naviUpdateListener;
    private List<String> naviUrlList;
    private NavigationObserver navigationObserver;

    public interface NaviUpdateListener {
        void onNaviUpdate();
    }

    private NavigationClient() {
        this.NAVI_SUFFIX = "navi.json";
        this.naviUrlList = new ArrayList();
        this.naviUpdateListener = null;
        this.latestTokenNaviList = new ArrayList();
        this.fetching = new AtomicBoolean(false);
        this.enableHttps = true;
        this.executor = Executors.newSingleThreadExecutor();
    }

    public static NavigationClient getInstance() {
        return SingletonHolder.sIns;
    }

    private static String getNavHost(String str) {
        try {
            URL url = new URL(str);
            String host = url.getHost();
            int port = url.getPort();
            if (port == -1 || url.getDefaultPort() == url.getPort()) {
                return host;
            }
            return host + ":" + port;
        } catch (MalformedURLException e) {
            RLog.e(TAG, "MalformedURLException ", e);
            return null;
        }
    }

    public void init(Context context) {
        this.enableHttps = NetUtils.isHttpsEnable(context);
        if (this.enableHttps) {
            this.naviUrlList.add(NAVIGATION_HTTPS_URL);
            this.naviUrlList.add(NAVIGATION_2_HTTPS_URL);
        } else {
            this.naviUrlList.add(NAVIGATION_HTTP_URL);
            this.naviUrlList.add(NAVIGATION_2_HTTP_URL);
        }
        this.naviString = listToString(this.naviUrlList);
    }

    private String listToString(List<?> list) {
        StringBuilder sb = new StringBuilder();
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i) != null && list.get(i) != "") {
                    sb.append(list.get(i));
                    sb.append(";");
                }
            }
        }
        return sb.toString();
    }

    public boolean isFetching() {
        return this.fetching.get();
    }

    public void setNaviDomainList(String str) {
        this.naviString = str;
        List<String> list = this.naviUrlList;
        if (list == null) {
            return;
        }
        list.clear();
        if (str == null) {
            return;
        }
        this.naviUrlList.addAll(naviStrToList(str, ";"));
        HttpDnsManager.getInstance().shouldEnableHttpDns(this.naviUrlList);
    }

    public List<String> getNaviUrlList() {
        return this.naviUrlList;
    }

    private List<String> naviStrToList(String str, String str2) {
        String[] split;
        ArrayList arrayList = new ArrayList();
        if (TextUtils.isEmpty(str)) {
            return arrayList;
        }
        for (String str3 : str.split(str2)) {
            if (!TextUtils.isEmpty(str3)) {
                String formatServerAddress = formatServerAddress(str3.trim(), "navi.json");
                if (!arrayList.contains(formatServerAddress)) {
                    arrayList.add(formatServerAddress);
                }
            }
        }
        return arrayList;
    }

    public String formatServerAddress(String str, String str2) {
        String str3;
        if (str.toLowerCase().startsWith("http")) {
            str3 = "%s/%s";
        } else {
            str3 = this.enableHttps ? "https://%s/%s" : "http://%s/%s";
        }
        return String.format(str3, str, str2);
    }

    public void addObserver(NavigationObserver navigationObserver) {
        this.navigationObserver = navigationObserver;
    }

    public void getCMPServerString(Context context, String str, String str2) {
        RLog.d(TAG, "[connect] getCMPServerString.");
        this.context = context.getApplicationContext();
        if (isNaviCacheValid(context, str, str2)) {
            RLog.d(TAG, "[connect] cache is valid.");
            this.navigationObserver.onSuccess(NavigationCacheHelper.getUserId(context));
            return;
        }
        String userId = NavigationCacheHelper.getUserId(context);
        if (!str2.equals(NavigationCacheHelper.getToken(context))) {
            NavigationCacheHelper.clearUserId(context);
            RLog.d(TAG, "[connect] clear userId.");
            userId = "";
        }
        if (CMPStrategy.getInstance().getCmpList().size() > 0) {
            RLog.d(TAG, "[connect] cache cmp length > 0.");
            this.navigationObserver.onSuccess(userId);
            return;
        }
        requestNavi(str, str2, true);
    }

    public boolean isNaviCacheValid(Context context, String str, String str2) {
        return NavigationCacheHelper.isCacheValid(context, str, str2, this.naviString);
    }

    public void requestNavi(final String str, final String str2, final boolean z) {
        this.executor.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    List<String> allNaviURLs = NavigationClient.this.getAllNaviURLs(str2);
                    if (allNaviURLs.size() > 0) {
                        NavigationClient.this.fetching.set(true);
                        for (String str3 : allNaviURLs) {
                            if (NavigationClient.this.request(str3, str, str2, z, allNaviURLs.indexOf(str3) == allNaviURLs.size() - 1)) {
                                break;
                            }
                        }
                        NavigationClient.this.fetching.set(false);
                    }
                } catch (Exception e) {
                    FwLog.write(1, 1, FwLog.LogTag.L_CRASH_IPC_EPT_F.getTag(), "stacks", FwLog.stackToString(e));
                    if (z) {
                        NavigationClient.this.navigationObserver.onError(NavigationCacheHelper.getUserId(NavigationClient.this.context), 30004);
                    }
                }
            }
        });
    }

    public boolean isMPOpened(Context context) {
        return NavigationCacheHelper.isMPOpened(context);
    }

    public boolean isGROpened(Context context) {
        return NavigationCacheHelper.isGetRemoteEnabled(context);
    }

    public int getGroupMessageLimit(Context context) {
        return NavigationCacheHelper.getGroupMessageLimit(context);
    }

    public boolean isUSOpened(Context context) {
        return NavigationCacheHelper.isUSOpened(context);
    }

    public String getUserId(Context context) {
        return NavigationCacheHelper.getUserId(context);
    }

    public String getPrimeP(Context context) {
        return NavigationCacheHelper.getPrimeP(context);
    }

    public String getPrimeG(Context context) {
        return NavigationCacheHelper.getPrimeG(context);
    }

    public String getKeyE(Context context) {
        return NavigationCacheHelper.getKeyE(context);
    }

    public String getKeyN(Context context) {
        return NavigationCacheHelper.getKeyN(context);
    }

    public long getRandomR(Context context) {
        return NavigationCacheHelper.getRandomR(context);
    }

    public int getAlgorithm(Context context) {
        return NavigationCacheHelper.getAlgorithm(context);
    }

    public String getSite(Context context) {
        return NavigationCacheHelper.getSite(context);
    }

    public boolean isRepairMsgEnabled(Context context) {
        return NavigationCacheHelper.isRepairMsgEnabled(context);
    }

    public void requestCmpIfNeed(Context context, final String str, final String str2) {
        if (NavigationCacheHelper.isCacheTimeout(context)) {
            this.executor.submit(new Runnable() {
                @Override
                public void run() {
                    NavigationClient.this.requestNavi(str, str2, true);
                }
            });
        }
    }

    public void clearCacheTime(Context context) {
        NavigationCacheHelper.updateTime(context, 0L);
    }

    public String getVoIPCallInfo(Context context) {
        return NavigationCacheHelper.getVoIPCallInfo(context);
    }

    public String getMediaServer(Context context) {
        return NavigationCacheHelper.getMediaServer(context);
    }

    public List<FilePlatformInfo> getMediaServerConfigs(Context context) {
        return NavigationCacheHelper.getMediaServerCache(context);
    }

    public boolean isGetRemoteHistoryEnabled(Context context) {
        return NavigationCacheHelper.isGetRemoteEnabled(context);
    }

    public boolean isChatroomHistoryEnabled(Context context) {
        return NavigationCacheHelper.isChatroomHistoryEnabled(context);
    }

    public boolean request(String str, String str2, String str3, boolean z, boolean z2) {
        String str4;
        Throwable th;
        HttpURLConnection httpURLConnection;
        BufferedInputStream bufferedInputStream;
        int i;
        String str5;
        long currentTimeMillis;
        HttpURLConnection createConnection;
        String str6;
        int responseCode;
        InputStream inputStream;
        Throwable th2;
        BufferedInputStream bufferedInputStream2;
        ByteArrayOutputStream byteArrayOutputStream;
        RLog.d(TAG, "[connect] request " + str + ", appKey:" + str2 + ", token: " + str3 + ", forceUpdate:" + z);
        URL urlStr = getUrlStr(str);
        String host = urlStr != null ? urlStr.getHost() : "";
        HttpURLConnection httpURLConnection2 = null;
        r16 = null;
        r16 = null;
        httpURLConnection2 = null;
        BufferedInputStream bufferedInputStream3 = null;
        boolean z3 = false;
        try {
            HashMap<String, String> httpDnsIps = HttpDnsManager.getInstance().getHttpDnsIps(this.context, host);
            String str7 = httpDnsIps.get("resolveIp");
            String str8 = httpDnsIps.get("clientIp");
            String tokenExceptNavi = getTokenExceptNavi(str3);
            if (TextUtils.isEmpty(str7)) {
                try {
                    String queryRequestIP = NavigationCacheHelper.queryRequestIP(str);
                    currentTimeMillis = System.currentTimeMillis();
                    FwLog.write(3, 1, FwLog.LogTag.L_GET_NAVI_T.getTag(), "url|ip", str, queryRequestIP);
                    str5 = "IOException ";
                    try {
                        createConnection = createConnection("", str, str2, tokenExceptNavi, "");
                        str6 = queryRequestIP;
                    } catch (Exception e) {
                        e = e;
                        bufferedInputStream = null;
                        str4 = str5;
                        i = -1;
                        try {
                            detectNaviIfNeed(this.context);
                            FwLog.write(1, 1, FwLog.LogTag.L_CRASH_IPC_EPT_F.getTag(), "stacks", FwLog.stackToString(e));
                            FwLog.write(3, 1, FwLog.LogTag.L_GET_NAVI_R.getTag(), "code|url", Integer.valueOf(i), str);
                            if (this.navigationObserver != null) {
                            }
                            RLog.e(TAG, "request exception.");
                            RLog.i(TAG, "request end: " + i + ", force = " + z);
                            if (bufferedInputStream != null) {
                            }
                            if (httpURLConnection2 != null) {
                            }
                            return z3;
                        } catch (Throwable th3) {
                            th = th3;
                            httpURLConnection = httpURLConnection2;
                            bufferedInputStream3 = bufferedInputStream;
                            RLog.i(TAG, "request end: " + i + ", force = " + z);
                            if (bufferedInputStream3 != null) {
                                try {
                                    bufferedInputStream3.close();
                                } catch (IOException e2) {
                                    RLog.e(TAG, str4, e2);
                                }
                            }
                            if (httpURLConnection != null) {
                                httpURLConnection.disconnect();
                            }
                            throw th;
                        }
                    } catch (Throwable th4) {
                        th = th4;
                        httpURLConnection = null;
                        str4 = str5;
                        i = -1;
                        RLog.i(TAG, "request end: " + i + ", force = " + z);
                        if (bufferedInputStream3 != null) {
                        }
                        if (httpURLConnection != null) {
                        }
                        throw th;
                    }
                } catch (Exception e3) {
                    e = e3;
                    str5 = "IOException ";
                } catch (Throwable th5) {
                    th = th5;
                    str4 = "IOException ";
                    httpURLConnection = null;
                    i = -1;
                    RLog.i(TAG, "request end: " + i + ", force = " + z);
                    if (bufferedInputStream3 != null) {
                    }
                    if (httpURLConnection != null) {
                    }
                    throw th;
                }
            } else {
                str5 = "IOException ";
                try {
                    currentTimeMillis = System.currentTimeMillis();
                    FwLog.write(3, 1, FwLog.LogTag.L_GET_NAVI_T.getTag(), "url|ip", str, str7);
                    RLog.i(TAG, "https connection ip = " + str7);
                    createConnection = createConnection(host, new URL(str.replaceFirst(host, str7)).toString(), str2, tokenExceptNavi, str8);
                    str6 = str7;
                } catch (Exception e4) {
                    e = e4;
                    str4 = str5;
                    bufferedInputStream = null;
                    i = -1;
                    detectNaviIfNeed(this.context);
                    FwLog.write(1, 1, FwLog.LogTag.L_CRASH_IPC_EPT_F.getTag(), "stacks", FwLog.stackToString(e));
                    FwLog.write(3, 1, FwLog.LogTag.L_GET_NAVI_R.getTag(), "code|url", Integer.valueOf(i), str);
                    if (this.navigationObserver != null) {
                        this.navigationObserver.onError(NavigationCacheHelper.getUserId(this.context), 30004);
                    }
                    RLog.e(TAG, "request exception.");
                    RLog.i(TAG, "request end: " + i + ", force = " + z);
                    if (bufferedInputStream != null) {
                    }
                    if (httpURLConnection2 != null) {
                    }
                    return z3;
                } catch (Throwable th6) {
                    th = th6;
                    str4 = str5;
                    th = th;
                    httpURLConnection = null;
                    i = -1;
                    RLog.i(TAG, "request end: " + i + ", force = " + z);
                    if (bufferedInputStream3 != null) {
                    }
                    if (httpURLConnection != null) {
                    }
                    throw th;
                }
            }
        } catch (Exception e5) {
            e = e5;
            str4 = "IOException ";
        } catch (Throwable th7) {
            th = th7;
            str4 = "IOException ";
        }
        try {
            createConnection.connect();
            responseCode = createConnection.getResponseCode();
            if (responseCode != 200) {
                try {
                    inputStream = createConnection.getErrorStream();
                } catch (Exception e6) {
                    e = e6;
                    i = responseCode;
                    bufferedInputStream = null;
                    str4 = str5;
                    httpURLConnection2 = createConnection;
                } catch (Throwable th8) {
                    th2 = th8;
                    httpURLConnection = createConnection;
                    i = responseCode;
                    str4 = str5;
                    th = th2;
                    RLog.i(TAG, "request end: " + i + ", force = " + z);
                    if (bufferedInputStream3 != null) {
                    }
                    if (httpURLConnection != null) {
                    }
                    throw th;
                }
            } else {
                try {
                    inputStream = createConnection.getInputStream();
                } catch (Exception e7) {
                    e = e7;
                    httpURLConnection = createConnection;
                    str4 = str5;
                    i = responseCode;
                    bufferedInputStream = null;
                    httpURLConnection2 = httpURLConnection;
                    detectNaviIfNeed(this.context);
                    FwLog.write(1, 1, FwLog.LogTag.L_CRASH_IPC_EPT_F.getTag(), "stacks", FwLog.stackToString(e));
                    FwLog.write(3, 1, FwLog.LogTag.L_GET_NAVI_R.getTag(), "code|url", Integer.valueOf(i), str);
                    if (this.navigationObserver != null) {
                    }
                    RLog.e(TAG, "request exception.");
                    RLog.i(TAG, "request end: " + i + ", force = " + z);
                    if (bufferedInputStream != null) {
                    }
                    if (httpURLConnection2 != null) {
                    }
                    return z3;
                } catch (Throwable th9) {
                    httpURLConnection = createConnection;
                    str4 = str5;
                    th = th9;
                    i = responseCode;
                    RLog.i(TAG, "request end: " + i + ", force = " + z);
                    if (bufferedInputStream3 != null) {
                    }
                    if (httpURLConnection != null) {
                    }
                    throw th;
                }
            }
            bufferedInputStream2 = new BufferedInputStream(inputStream);
            try {
                byteArrayOutputStream = new ByteArrayOutputStream(512);
            } catch (Exception e8) {
                e = e8;
                httpURLConnection = createConnection;
            } catch (Throwable th10) {
                th = th10;
                httpURLConnection = createConnection;
            }
        } catch (Exception e9) {
            e = e9;
            str4 = str5;
            bufferedInputStream = null;
            httpURLConnection2 = createConnection;
            i = -1;
            detectNaviIfNeed(this.context);
            FwLog.write(1, 1, FwLog.LogTag.L_CRASH_IPC_EPT_F.getTag(), "stacks", FwLog.stackToString(e));
            FwLog.write(3, 1, FwLog.LogTag.L_GET_NAVI_R.getTag(), "code|url", Integer.valueOf(i), str);
            if (this.navigationObserver != null) {
            }
            RLog.e(TAG, "request exception.");
            RLog.i(TAG, "request end: " + i + ", force = " + z);
            if (bufferedInputStream != null) {
            }
            if (httpURLConnection2 != null) {
            }
            return z3;
        } catch (Throwable th11) {
            httpURLConnection = createConnection;
            str4 = str5;
            th = th11;
            i = -1;
            RLog.i(TAG, "request end: " + i + ", force = " + z);
            if (bufferedInputStream3 != null) {
            }
            if (httpURLConnection != null) {
            }
            throw th;
        }
        while (true) {
            int read = bufferedInputStream2.read();
            if (read == -1) {
                break;
            }
            try {
                byteArrayOutputStream.write(read);
            } catch (Exception e10) {
                e = e10;
                httpURLConnection2 = createConnection;
                i = responseCode;
                bufferedInputStream = bufferedInputStream2;
            } catch (Throwable th12) {
                th2 = th12;
                httpURLConnection = createConnection;
                i = responseCode;
                bufferedInputStream3 = bufferedInputStream2;
                str4 = str5;
                th = th2;
                RLog.i(TAG, "request end: " + i + ", force = " + z);
                if (bufferedInputStream3 != null) {
                }
                if (httpURLConnection != null) {
                }
                throw th;
            }
            str4 = str5;
            detectNaviIfNeed(this.context);
            FwLog.write(1, 1, FwLog.LogTag.L_CRASH_IPC_EPT_F.getTag(), "stacks", FwLog.stackToString(e));
            FwLog.write(3, 1, FwLog.LogTag.L_GET_NAVI_R.getTag(), "code|url", Integer.valueOf(i), str);
            if (this.navigationObserver != null && z2 && z) {
                this.navigationObserver.onError(NavigationCacheHelper.getUserId(this.context), 30004);
            }
            RLog.e(TAG, "request exception.");
            RLog.i(TAG, "request end: " + i + ", force = " + z);
            if (bufferedInputStream != null) {
                try {
                    bufferedInputStream.close();
                } catch (IOException e11) {
                    RLog.e(TAG, str4, e11);
                }
            }
            if (httpURLConnection2 != null) {
                httpURLConnection2.disconnect();
            }
            return z3;
        }
        String trim = new String(byteArrayOutputStream.toByteArray(), "utf-8").trim();
        long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis;
        String tag = FwLog.LogTag.L_GET_NAVI_R.getTag();
        httpURLConnection = createConnection;
        Object[] objArr = new Object[4];
        objArr[0] = Integer.valueOf(responseCode);
        bufferedInputStream = bufferedInputStream2;
        objArr[1] = str;
        objArr[2] = Long.valueOf(currentTimeMillis2);
        objArr[3] = str6;
        FwLog.write(3, 1, tag, "code|url|duration|ip", objArr);
        int decode2File = NavigationCacheHelper.decode2File(this.context, trim, responseCode);
        String userId = NavigationCacheHelper.getUserId(this.context);
        if (decode2File == 0) {
            FwLog.write(3, 1, FwLog.LogTag.L_DECODE_NAVI_S.getTag(), "code", Integer.valueOf(decode2File));
            NavigationCacheHelper.clearComplexConnectionEntries(this.context);
            CMPStrategy.getInstance().onGetCmpEntriesFromNavi();
            if (z) {
                this.navigationObserver.onSuccess(userId);
            }
            NavigationCacheHelper.cacheRequest(this.context, str2, str3);
            NavigationCacheHelper.cacheLastSuccessNaviDomainList(this.context, this.naviString);
            notifyNaviUpdate();
            z3 = true;
        } else {
            detectNaviIfNeed(this.context);
            FwLog.write(1, 1, FwLog.LogTag.L_DECODE_NAVI_S.getTag(), "code|data", Integer.valueOf(decode2File), trim.replaceAll("\\n", ""));
            NavigationObserver navigationObserver = this.navigationObserver;
            if (navigationObserver != null && z2 && z) {
                navigationObserver.onError(userId, decode2File);
            }
            RLog.e(TAG, "request failure : " + decode2File + ", data = " + trim);
        }
        RLog.i(TAG, "request end: " + responseCode + ", force = " + z);
        bufferedInputStream.close();
        if (httpURLConnection != null) {
            httpURLConnection.disconnect();
        }
        return z3;
    }

    private URL getUrlStr(String str) {
        try {
            return new URL(str);
        } catch (MalformedURLException e) {
            RLog.e(TAG, "getUrlStr ", e);
            return null;
        }
    }

    private HttpURLConnection createConnection(String str, final String str2, String str3, String str4, String str5) throws IOException {
        HttpURLConnection createURLConnection = NetUtils.createURLConnection(str2);
        createURLConnection.setConnectTimeout(RCEvent.EVENT_SUBSCRIBE_LIVE_STREAM);
        createURLConnection.setReadTimeout(10000);
        createURLConnection.setUseCaches(false);
        createURLConnection.setRequestMethod("POST");
        createURLConnection.setRequestProperty(BaseRequest.HEADER_CONNECTION, "Close");
        createURLConnection.setRequestProperty("User-Agent", LibStorageUtils.DIR);
        if (TextUtils.isEmpty(str)) {
            str = getNavHost(str2);
        }
        if (!TextUtils.isEmpty(str5)) {
            createURLConnection.setRequestProperty("clientIp", str5);
            NavigationCacheHelper.updateClientIp(this.context, str5);
        }
        if (!TextUtils.isEmpty(str)) {
            createURLConnection.setRequestProperty("Host", str);
            if (createURLConnection instanceof HttpsURLConnection) {
                if (SSLUtils.getSSLContext() == null) {
                    HttpsURLConnection httpsURLConnection = (HttpsURLConnection) createURLConnection;
                    httpsURLConnection.setSSLSocketFactory(new TlsSniSocketFactory(httpsURLConnection));
                }
                if (SSLUtils.getHostVerifier() == null) {
                    ((HttpsURLConnection) createURLConnection).setHostnameVerifier(new HostnameVerifier() {
                        @Override
                        public boolean verify(String str6, SSLSession sSLSession) {
                            return !TextUtils.isEmpty(str2) && str2.contains(str6);
                        }
                    });
                }
            }
        }
        String str6 = (("token=" + URLEncoder.encode(str4, Key.STRING_CHARSET_NAME)) + "&v=5.1.3.5") + "&p=Android";
        createURLConnection.setRequestProperty("Content-Length", String.valueOf(str6.length()));
        createURLConnection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
        createURLConnection.setRequestProperty("appId", str3);
        createURLConnection.setDoOutput(true);
        createURLConnection.setDoInput(true);
        OutputStream outputStream = createURLConnection.getOutputStream();
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, Key.STRING_CHARSET_NAME));
        bufferedWriter.write(str6);
        bufferedWriter.flush();
        bufferedWriter.close();
        outputStream.close();
        return createURLConnection;
    }

    public String getNaviString() {
        return this.naviString;
    }

    private List<String> getNaviFromToken(String str) {
        ArrayList arrayList = new ArrayList();
        String[] split = str.split(NAVI_IN_TOKEN_SPLIT_SYMBOL);
        if (split.length > 1) {
            String str2 = split[1];
            if (!TextUtils.isEmpty(str2)) {
                if (!str2.equals(this.latestTokenNaviEncodeStr)) {
                    arrayList.addAll(naviStrToList(str2, ";"));
                    this.latestTokenNaviList.clear();
                    this.latestTokenNaviList.addAll(arrayList);
                    this.latestTokenNaviEncodeStr = str2;
                } else {
                    arrayList.addAll(this.latestTokenNaviList);
                }
            }
        }
        return arrayList;
    }

    public String getTokenExceptNavi(String str) {
        return (TextUtils.isEmpty(str) || !str.contains(NAVI_IN_TOKEN_SPLIT_SYMBOL)) ? str : str.substring(0, str.indexOf(NAVI_IN_TOKEN_SPLIT_SYMBOL) + 1);
    }

    public void setNaviUpdateListener(NaviUpdateListener naviUpdateListener) {
        this.naviUpdateListener = naviUpdateListener;
    }

    private void notifyNaviUpdate() {
        NaviUpdateListener naviUpdateListener = this.naviUpdateListener;
        if (naviUpdateListener != null) {
            naviUpdateListener.onNaviUpdate();
        }
    }

    public String getUploadLogConfigInfo(Context context) {
        return NavigationCacheHelper.getRealTimeLogConfig(context);
    }

    public List<String> getAllNaviURLs(String str) {
        ArrayList arrayList = new ArrayList();
        List<String> naviFromToken = getNaviFromToken(str);
        if (naviFromToken.size() > 0) {
            arrayList.addAll(naviFromToken);
        }
        for (String str2 : this.naviUrlList) {
            if (!arrayList.contains(str2)) {
                arrayList.add(str2);
            }
        }
        FwLog.write(3, 1, FwLog.LogTag.L_NAVI_INFO_S.getTag(), "token|navis", str, SystemUtils.listToString(arrayList));
        return arrayList;
    }

    private void detectNaviIfNeed(Context context) {
        NetDetection.detectNavi(context, false, new NetDetection.DetectionCallback() {
            @Override
            public void onError() {
            }

            @Override
            public void onSuccess(String str, String str2, String str3) {
                FwLog.write(1, 1, FwLog.LogTag.L_DETECT_NAVI_S.getTag(), "navi|ip|net", str, str2, str3);
            }
        });
    }

    public static class SingletonHolder {
        private static final NavigationClient sIns = new NavigationClient();

        private SingletonHolder() {
        }
    }
}