package io.rong.imlib.navigation; import android.annotation.SuppressLint; import android.content.Context; import android.text.TextUtils; import cn.rongcloud.wrapper.CrashConstant; import com.tencent.imsdk.BaseConstants; import com.xiaomi.mipush.sdk.Constants; 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.IRongCoreEnum; import io.rong.imlib.RongCoreClient; import io.rong.imlib.RongCoreClientImpl; import io.rong.imlib.common.ExecutorFactory; import io.rong.imlib.common.NetUtils; import io.rong.imlib.filetransfer.upload.FilePlatformInfo; import io.rong.imlib.navigation.NetDetection; import io.rong.imlib.stats.QAStatisticsHelper; import io.rong.imlib.stats.StatsDataManager; 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.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSession; import t4.h; import u6.i; 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_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 NAVI_SUFFIX = "navi.json"; private static final String SEP1 = ";"; private static final String TAG = "NavigationClient"; private Context context; public boolean enableHttpDns; private boolean enableHttpDnsRequest; private volatile boolean enableHttps; private final ExecutorService executor; private final AtomicBoolean fetching; private String latestTokenNaviEncodeStr; private final List<String> latestTokenNaviList; private String naviString; private NaviUpdateListener naviUpdateListener; private List<String> naviUrlList; private List<NavigationObserver> navigationObservers; public interface NaviUpdateListener { void onNaviUpdate(); } public static class SingletonHolder { @SuppressLint({"StaticFieldLeak"}) private static final NavigationClient sIns = new NavigationClient(); private SingletonHolder() { } } private HttpURLConnection createConnection(String str, String str2, String str3, String str4, String str5) throws IOException { HttpURLConnection createURLConnection = NetUtils.createURLConnection(str2); createURLConnection.setConnectTimeout(5000); createURLConnection.setReadTimeout(10000); createURLConnection.setUseCaches(false); createURLConnection.setRequestMethod("POST"); createURLConnection.setRequestProperty("Connection", "Close"); createURLConnection.setRequestProperty("User-Agent", LibStorageUtils.DIR); 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 c(str2)); } } } String str6 = (("token=" + URLEncoder.encode(str4, "UTF-8")) + "&v=" + RongCoreClient.getVersion()) + "&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, StandardCharsets.UTF_8)); bufferedWriter.write(str6); bufferedWriter.flush(); bufferedWriter.close(); outputStream.close(); return createURLConnection; } private void decode2FileError(boolean z10, boolean z11, URL url, String str, String str2, long j10, long j11, int i10, String str3, int i11, String str4) { String str5; int i12; detectNaviIfNeed(this.context); FwLog.write(1, 1, FwLog.LogTag.L_DECODE_NAVI_S.getTag(), "code|data", Integer.valueOf(i11), str3.replaceAll("\\n", "")); QAStatisticsHelper qAStatisticsHelper = QAStatisticsHelper.INSTANCE; if (url == null) { str5 = ""; } else { str5 = url.getHost(); } if (url == null) { i12 = 0; } else { i12 = url.getPort(); } qAStatisticsHelper.reqNaviComplete(str5, i12, str, str2, i10, j10, i11, j11); if (z11 && z10) { onNaviError(str4, i11); } RLog.e(TAG, "request failure : " + i11 + ", data = " + str3); } private boolean decode2FileSuccess(String str, String str2, boolean z10, URL url, String str3, String str4, long j10, long j11, int i10, int i11, String str5) { int i12; int i13 = 0; FwLog.write(3, 1, FwLog.LogTag.L_DECODE_NAVI_S.getTag(), "code", Integer.valueOf(i11)); String str6 = ""; if (RongCoreClientImpl.isPrivateSDK() || !NavigationCacheHelper.getPrivateCloudConfig(this.context)) { NavigationCacheHelper.clearComplexConnectionEntries(this.context); CMPStrategy.getInstance().onGetCmpEntriesFromNavi(); QAStatisticsHelper qAStatisticsHelper = QAStatisticsHelper.INSTANCE; if (url != null) { str6 = url.getHost(); } if (url == null) { i12 = 0; } else { i12 = url.getPort(); } qAStatisticsHelper.reqNaviComplete(str6, i12, str3, str4, i10, j10, 0, j11); if (z10) { onNaviSuccess(str5); } NavigationCacheHelper.cacheRequest(this.context, str, str2); NavigationCacheHelper.cacheLastSuccessNaviDomainList(this.context, this.naviString); notifyNaviUpdate(); return false; } QAStatisticsHelper qAStatisticsHelper2 = QAStatisticsHelper.INSTANCE; if (url != null) { str6 = url.getHost(); } if (url != null) { i13 = url.getPort(); } IRongCoreEnum.CoreErrorCode coreErrorCode = IRongCoreEnum.CoreErrorCode.RC_ENVIRONMENT_ERROR; qAStatisticsHelper2.reqNaviComplete(str6, i13, str3, str4, i10, j10, coreErrorCode.getValue(), j11); if (z10) { NavigationCacheHelper.clearCache(this.context); onNaviError(str5, coreErrorCode.getValue()); } return true; } private void detectNaviIfNeed(Context context2) { NetDetection.detectNavi(context2, false, new NetDetection.DetectionCallback() { /* class io.rong.imlib.navigation.NavigationClient.AnonymousClass1 */ @Override // io.rong.imlib.navigation.NetDetection.DetectionCallback public void onError() { RLog.e(NavigationClient.TAG, "detectNaviIfNeed onError"); } @Override // io.rong.imlib.navigation.NetDetection.DetectionCallback 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); } }); } private void enableDnsRequest(List<String> list, boolean z10) { if (z10) { String queryRequestIP = NavigationCacheHelper.queryRequestIP(list.get(0)); if ("0.0.0.0".equals(queryRequestIP) || i.f136122i.equals(queryRequestIP)) { this.enableHttpDnsRequest = true; FwLog.write(1, 1, FwLog.LogTag.L_GET_ALL_NAVI_S.getTag(), "hosts", SystemUtils.listToString(list)); } } } private void freeObject(boolean z10, HttpURLConnection httpURLConnection, BufferedInputStream bufferedInputStream, int i10) { RLog.i(TAG, "request end: " + i10 + ", force = " + z10); if (bufferedInputStream != null) { try { bufferedInputStream.close(); } catch (IOException e10) { RLog.e(TAG, "IOException ", e10); } } if (httpURLConnection != null) { httpURLConnection.disconnect(); } } private List<String> getAllNaviURLs(String str) { ArrayList arrayList = new ArrayList(); List<String> naviFromToken = getNaviFromToken(str); if (!naviFromToken.isEmpty()) { 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 ByteArrayOutputStream getByteArrayOutputStream(BufferedInputStream bufferedInputStream) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(512); while (true) { int read = bufferedInputStream.read(); if (read == -1) { return byteArrayOutputStream; } byteArrayOutputStream.write(read); } } private long getDelta(String str, int i10, long j10, String str2) { long currentTimeMillis = System.currentTimeMillis() - j10; FwLog.write(3, 1, FwLog.LogTag.L_GET_NAVI_R.getTag(), "code|url|duration|ip", Integer.valueOf(i10), str, Long.valueOf(currentTimeMillis), str2); return currentTimeMillis; } private InputStream getInputStream(HttpURLConnection httpURLConnection, int i10) throws IOException { if (i10 != 200) { return httpURLConnection.getErrorStream(); } return httpURLConnection.getInputStream(); } 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 + Constants.COLON_SEPARATOR + port; } catch (MalformedURLException e10) { RLog.e(TAG, "MalformedURLException ", e10); return null; } } 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, h.f134437b)); this.latestTokenNaviList.clear(); this.latestTokenNaviList.addAll(arrayList); this.latestTokenNaviEncodeStr = str2; } else { arrayList.addAll(this.latestTokenNaviList); } } } return arrayList; } private URL getUrlStr(String str) { try { return new URL(str); } catch (MalformedURLException e10) { RLog.e(TAG, "getUrlStr ", e10); return null; } } /* access modifiers changed from: private */ public static /* synthetic */ boolean lambda$createConnection$2(String str, String str2, SSLSession sSLSession) { return !TextUtils.isEmpty(str) && str.contains(str2); } /* access modifiers changed from: private */ public /* synthetic */ void lambda$requestCmpIfNeed$1(String str, String str2) { requestNavi(str, str2, true); } /* access modifiers changed from: private */ public /* synthetic */ void lambda$requestNavi$0(String str, String str2, boolean z10) { try { List<String> allNaviURLs = getAllNaviURLs(str); this.enableHttpDnsRequest = this.enableHttpDns && this.enableHttpDnsRequest; if (!allNaviURLs.isEmpty()) { this.fetching.set(true); boolean z11 = false; for (String str3 : allNaviURLs) { z11 = allNaviURLs.indexOf(str3) == allNaviURLs.size() - 1; if (request(str3, str2, str, z10, z11, this.enableHttpDnsRequest)) { this.fetching.set(false); return; } } enableDnsRequest(allNaviURLs, z11); this.fetching.set(false); } } catch (Exception e10) { FwLog.write(1, 1, FwLog.LogTag.L_CRASH_IPC_EPT_F.getTag(), CrashConstant.CRASH_STACK_KEY, FwLog.stackToString(e10)); if (z10) { onNaviError(NavigationCacheHelper.getUserId(this.context), BaseConstants.ERR_SVR_FRIENDSHIP_ADMIN_REQUIRED); } } } private String listToString(List<?> list) { StringBuilder sb2 = new StringBuilder(); if (list != null && !list.isEmpty()) { for (int i10 = 0; i10 < list.size(); i10++) { if (list.get(i10) != null && !"".equals(list.get(i10))) { sb2.append(list.get(i10)); sb2.append(h.f134437b); } } } return sb2.toString(); } private List<String> naviStrToList(String str, String str2) { ArrayList arrayList = new ArrayList(); if (TextUtils.isEmpty(str)) { return arrayList; } String[] split = str.split(str2); for (String str3 : split) { if (!TextUtils.isEmpty(str3)) { String formatServerAddress = formatServerAddress(str3.trim(), NAVI_SUFFIX); if (!arrayList.contains(formatServerAddress)) { arrayList.add(formatServerAddress); } } } return arrayList; } private void notifyNaviUpdate() { NaviUpdateListener naviUpdateListener2 = this.naviUpdateListener; if (naviUpdateListener2 != null) { naviUpdateListener2.onNaviUpdate(); } } private void observerError(boolean z10, boolean z11) { if (z11 && z10) { onNaviError(NavigationCacheHelper.getUserId(this.context), BaseConstants.ERR_SVR_FRIENDSHIP_ADMIN_REQUIRED); } } private void recordNavi(URL url) { StatsDataManager.getInstance().recordNavi(false, url != null ? url.getHost() : null, -1); } /* JADX DEBUG: Multi-variable search result rejected for r1v36, resolved type: boolean */ /* JADX DEBUG: Multi-variable search result rejected for r1v40, resolved type: boolean */ /* JADX DEBUG: Multi-variable search result rejected for r1v41, resolved type: boolean */ /* JADX DEBUG: Multi-variable search result rejected for r6v18, resolved type: boolean */ /* JADX WARN: Multi-variable type inference failed */ /* JADX WARNING: Code restructure failed: missing block: B:115:0x029c, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:116:0x029d, code lost: r2 = r36; r14 = r38; r5 = r40; r4 = r21; r1 = r24; r13 = r29; */ /* JADX WARNING: Code restructure failed: missing block: B:118:0x02af, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:119:0x02b0, code lost: r14 = r38; r5 = r40; r4 = r21; r1 = r24; */ /* JADX WARNING: Code restructure failed: missing block: B:120:0x02b9, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:121:0x02ba, code lost: r2 = r36; r14 = r38; r5 = r40; r4 = r21; r1 = r24; r13 = r29; */ /* JADX WARNING: Code restructure failed: missing block: B:136:0x031f, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:137:0x0320, code lost: r14 = r38; r28 = null; r11 = r8; r5 = r25; */ /* JADX WARNING: Code restructure failed: missing block: B:139:0x032d, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:140:0x032e, code lost: r14 = r38; r13 = r10; r4 = r8; r11 = r17; r6 = r20; r5 = r23; r12 = r25; r7 = r26; r3 = null; */ /* JADX WARNING: Code restructure failed: missing block: B:141:0x0342, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:142:0x0343, code lost: r14 = r38; r13 = r10; r28 = null; r6 = ""; r5 = r9; */ /* JADX WARNING: Code restructure failed: missing block: B:143:0x034b, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:144:0x034c, code lost: r14 = r38; r28 = null; r1 = r0; r5 = -1; */ /* JADX WARNING: Code restructure failed: missing block: B:41:0x00c9, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:42:0x00ca, code lost: r14 = r38; r4 = r1; r6 = r2; */ /* JADX WARNING: Code restructure failed: missing block: B:43:0x00cf, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:44:0x00d0, code lost: r14 = r38; r5 = -1; */ /* JADX WARNING: Code restructure failed: missing block: B:54:0x00f2, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:55:0x00f3, code lost: r25 = -1; r13 = 1; r14 = r38; r5 = ""; r6 = r5; */ /* JADX WARNING: Code restructure failed: missing block: B:58:0x0102, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:59:0x0103, code lost: r14 = r38; r1 = r0; r0 = null; */ /* JADX WARNING: Code restructure failed: missing block: B:60:0x010b, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:61:0x010c, code lost: r14 = r38; r5 = ""; r6 = r5; r3 = null; r4 = null; r11 = 1; r12 = -1; r7 = -1; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:118:0x02af A[ExcHandler: all (th java.lang.Throwable), PHI: r15 r21 r24 r40 PHI: (r15v8 io.rong.imlib.navigation.NavigationClient) = (r15v9 io.rong.imlib.navigation.NavigationClient), (r15v9 io.rong.imlib.navigation.NavigationClient), (r15v9 io.rong.imlib.navigation.NavigationClient), (r15v9 io.rong.imlib.navigation.NavigationClient), (r15v14 io.rong.imlib.navigation.NavigationClient), (r15v14 io.rong.imlib.navigation.NavigationClient) binds: [B:94:0x0244, B:95:?, B:110:0x0282, B:111:?, B:91:0x023f, B:92:?] A[DONT_GENERATE, DONT_INLINE] PHI: (r21v0 int) = (r21v1 int), (r21v1 int), (r21v1 int), (r21v1 int), (r21v2 int), (r21v2 int) binds: [B:94:0x0244, B:95:?, B:110:0x0282, B:111:?, B:91:0x023f, B:92:?] A[DONT_GENERATE, DONT_INLINE] PHI: (r24v0 java.net.HttpURLConnection) = (r24v1 java.net.HttpURLConnection), (r24v1 java.net.HttpURLConnection), (r24v1 java.net.HttpURLConnection), (r24v1 java.net.HttpURLConnection), (r24v2 java.net.HttpURLConnection), (r24v2 java.net.HttpURLConnection) binds: [B:94:0x0244, B:95:?, B:110:0x0282, B:111:?, B:91:0x023f, B:92:?] A[DONT_GENERATE, DONT_INLINE] PHI: (r40v1 java.io.BufferedInputStream) = (r40v2 java.io.BufferedInputStream), (r40v2 java.io.BufferedInputStream), (r40v2 java.io.BufferedInputStream), (r40v2 java.io.BufferedInputStream), (r40v3 java.io.BufferedInputStream), (r40v3 java.io.BufferedInputStream) binds: [B:94:0x0244, B:95:?, B:110:0x0282, B:111:?, B:91:0x023f, B:92:?] A[DONT_GENERATE, DONT_INLINE], Splitter:B:91:0x023f] */ /* JADX WARNING: Removed duplicated region for block: B:136:0x031f A[ExcHandler: all (th java.lang.Throwable), Splitter:B:70:0x0154] */ /* JADX WARNING: Removed duplicated region for block: B:143:0x034b A[ExcHandler: all (r0v43 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:64:0x0120] */ /* JADX WARNING: Removed duplicated region for block: B:43:0x00cf A[ExcHandler: all (th java.lang.Throwable), Splitter:B:31:0x00a6] */ /* JADX WARNING: Removed duplicated region for block: B:58:0x0102 A[ExcHandler: all (r0v47 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:9:0x002c] */ private boolean request(String str, String str2, String str3, boolean z10, boolean z11, boolean z12) { String str4; boolean z13; Throwable th2; BufferedInputStream bufferedInputStream; HttpURLConnection httpURLConnection; Throwable th3; URL url; int i10; int i11; long j10; long j11; String str5; String str6; HttpURLConnection httpURLConnection2; BufferedInputStream bufferedInputStream2; Exception e10; int i12; BufferedInputStream bufferedInputStream3; int i13; long j12; String str7; String str8; int i14; int i15; HttpURLConnection httpURLConnection3; long delta; int responseCode; HttpURLConnection httpURLConnection4; BufferedInputStream bufferedInputStream4; BufferedInputStream bufferedInputStream5; HttpURLConnection httpURLConnection5; int i16; long j13; URL url2; String str9; int i17; boolean z14; long j14; String str10; long currentTimeMillis; String str11; NavigationClient navigationClient = this; writeRequestLog(str, str2, str3, z10); URL urlStr = getUrlStr(str); if (urlStr != null) { str4 = urlStr.getHost(); } else { str4 = ""; } HttpURLConnection httpURLConnection6 = null; boolean z15 = false; int i18 = -1; try { String tokenExceptNavi = navigationClient.getTokenExceptNavi(str3); long currentTimeMillis2 = System.currentTimeMillis(); if (z12) { try { long currentTimeMillis3 = System.currentTimeMillis(); HashMap<String, Object> httpDnsIps = HttpDnsManager.getInstance().getHttpDnsIps(navigationClient.context, str4); currentTimeMillis = System.currentTimeMillis() - currentTimeMillis3; str11 = (String) httpDnsIps.get("resolveIp"); String str12 = (String) httpDnsIps.get("clientIp"); if (TextUtils.isEmpty(str11)) { try { RLog.i(TAG, "bd dns resolve fail"); navigationClient.observerError(z10, z11); navigationClient.freeObject(z10, null, null, -1); return false; } catch (Exception e11) { e10 = e11; i10 = -1; str5 = ""; str6 = str11; bufferedInputStream2 = null; httpURLConnection2 = null; z13 = z10; j11 = currentTimeMillis; i11 = 1; url = urlStr; j10 = -1; try { navigationClient.detectNaviIfNeed(navigationClient.context); } catch (Throwable th4) { th3 = th4; httpURLConnection6 = bufferedInputStream2; httpURLConnection = httpURLConnection2; i12 = i10; i18 = i12; th2 = th3; bufferedInputStream = httpURLConnection6; httpURLConnection6 = httpURLConnection; navigationClient.freeObject(z13, httpURLConnection6, bufferedInputStream, i18); throw th2; } try { writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th5) { th3 = th5; httpURLConnection6 = bufferedInputStream2; httpURLConnection = httpURLConnection2; i12 = i10; i18 = i12; th2 = th3; bufferedInputStream = httpURLConnection6; httpURLConnection6 = httpURLConnection; navigationClient.freeObject(z13, httpURLConnection6, bufferedInputStream, i18); throw th2; } } catch (Throwable th6) { th2 = th6; bufferedInputStream = null; z13 = z10; navigationClient.freeObject(z13, httpURLConnection6, bufferedInputStream, i18); throw th2; } } else { RLog.i(TAG, "bd dns connection ip = " + str11); i13 = -1; i15 = 1; try { httpURLConnection = createConnection(str4, new URL(str.replaceFirst(str4, str11)).toString(), str2, tokenExceptNavi, str12); try { String str13 = (String) httpDnsIps.get(HttpDnsManager.KEY_DNS_SERVER_IP); Boolean bool = (Boolean) httpDnsIps.get(HttpDnsManager.KEY_FROM_CACHE); if (bool != null && bool.booleanValue()) { currentTimeMillis = 0; } httpURLConnection3 = httpURLConnection; str8 = str13; i14 = 1; j12 = currentTimeMillis; str7 = str11; } catch (Exception e12) { e10 = e12; z13 = z10; httpURLConnection2 = httpURLConnection; str5 = ""; str6 = str11; bufferedInputStream2 = null; i11 = i15; j11 = currentTimeMillis; i10 = i13; url = urlStr; j10 = -1; navigationClient.detectNaviIfNeed(navigationClient.context); writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th7) { } } catch (Exception e13) { e10 = e13; z13 = z10; str5 = ""; str6 = str11; bufferedInputStream2 = null; httpURLConnection2 = null; i11 = i15; j11 = currentTimeMillis; i10 = i13; url = urlStr; j10 = -1; navigationClient.detectNaviIfNeed(navigationClient.context); writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th8) { z13 = z10; th2 = th8; bufferedInputStream = null; i18 = -1; navigationClient.freeObject(z13, httpURLConnection6, bufferedInputStream, i18); throw th2; } } } catch (Exception e14) { e10 = e14; i13 = -1; i15 = 1; z13 = z10; str5 = ""; str6 = str11; bufferedInputStream2 = null; httpURLConnection2 = null; i11 = i15; j11 = currentTimeMillis; i10 = i13; url = urlStr; j10 = -1; navigationClient.detectNaviIfNeed(navigationClient.context); writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th9) { } } else { i13 = -1; i15 = 1; try { String queryRequestIP = NavigationCacheHelper.queryRequestIP(str); RLog.i(TAG, "system connection ip = " + queryRequestIP); httpURLConnection3 = createConnection(getNavHost(str), str, str2, tokenExceptNavi, ""); str8 = ""; str7 = queryRequestIP; i14 = 0; j12 = -1; } catch (Exception e15) { e10 = e15; z13 = z10; url = urlStr; bufferedInputStream3 = null; str6 = ""; str5 = str6; i11 = 0; i10 = i13; bufferedInputStream2 = bufferedInputStream3; httpURLConnection2 = bufferedInputStream2; j11 = -1; j10 = -1; navigationClient.detectNaviIfNeed(navigationClient.context); writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th10) { } } try { String tag = FwLog.LogTag.L_GET_NAVI_T.getTag(); Object[] objArr = new Object[2]; objArr[0] = str; objArr[i15] = str7; FwLog.write(3, i15, tag, "url|ip", objArr); httpURLConnection3.connect(); delta = getDelta(str, -1, currentTimeMillis2, str7); responseCode = httpURLConnection3.getResponseCode(); try { bufferedInputStream4 = new BufferedInputStream(navigationClient.getInputStream(httpURLConnection3, responseCode)); } catch (Exception e16) { e10 = e16; z13 = z10; httpURLConnection4 = httpURLConnection3; url = urlStr; j10 = delta; i10 = responseCode; i11 = i14; str5 = str8; str6 = str7; j11 = j12; bufferedInputStream2 = null; httpURLConnection2 = httpURLConnection4; navigationClient.detectNaviIfNeed(navigationClient.context); writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th11) { Throwable th12 = th11; z13 = z10; BufferedInputStream bufferedInputStream6 = null; httpURLConnection6 = httpURLConnection3; i18 = responseCode; th2 = th12; bufferedInputStream = bufferedInputStream6; navigationClient.freeObject(z13, httpURLConnection6, bufferedInputStream, i18); throw th2; } } catch (Exception e17) { e10 = e17; z13 = z10; url = urlStr; httpURLConnection2 = httpURLConnection3; j10 = delta; i11 = i14; str5 = str8; str6 = str7; i10 = i13; j11 = j12; bufferedInputStream2 = null; navigationClient.detectNaviIfNeed(navigationClient.context); writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th13) { } try { String trim = new String(navigationClient.getByteArrayOutputStream(bufferedInputStream4).toByteArray(), StandardCharsets.UTF_8).trim(); int decode2File = NavigationCacheHelper.decode2File(navigationClient.context, trim, responseCode); String userId = NavigationCacheHelper.getUserId(navigationClient.context); if (decode2File == 0) { j13 = delta; httpURLConnection5 = httpURLConnection3; bufferedInputStream5 = bufferedInputStream4; url2 = urlStr; str9 = null; i17 = i15; i16 = responseCode; try { if (decode2FileSuccess(str2, str3, z10, urlStr, str7, str8, j12, j13, i14, decode2File, userId)) { freeObject(z10, httpURLConnection5, bufferedInputStream5, i16); return false; } navigationClient = this; z14 = i17; } catch (Exception e18) { e10 = e18; i10 = i16; j10 = j13; bufferedInputStream2 = bufferedInputStream5; httpURLConnection2 = httpURLConnection5; z13 = z10; i11 = i14; str5 = str8; str6 = str7; j11 = j12; url = url2; navigationClient = this; navigationClient.detectNaviIfNeed(navigationClient.context); writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th14) { th2 = th14; bufferedInputStream = bufferedInputStream5; i18 = i16; httpURLConnection6 = httpURLConnection5; z13 = z10; navigationClient = this; navigationClient.freeObject(z13, httpURLConnection6, bufferedInputStream, i18); throw th2; } } else { j13 = delta; url2 = urlStr; str9 = null; i17 = i15; bufferedInputStream5 = bufferedInputStream4; i16 = responseCode; httpURLConnection5 = httpURLConnection3; navigationClient = navigationClient; try { decode2FileError(z10, z11, url2, str7, str8, j12, j13, i14, trim, decode2File, userId); z14 = false; } catch (Exception e19) { e10 = e19; z13 = z10; BufferedInputStream bufferedInputStream7 = bufferedInputStream5; int i19 = i16; httpURLConnection4 = httpURLConnection5; j10 = j14; i10 = i19; bufferedInputStream2 = bufferedInputStream7; z15 = z14 ? 1 : 0; i11 = i14; str5 = str8; str6 = str7; j11 = j12; httpURLConnection2 = httpURLConnection4; navigationClient.detectNaviIfNeed(navigationClient.context); writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th15) { } } StatsDataManager instance = StatsDataManager.getInstance(); boolean z16 = decode2File == 0 ? i17 : false; url = url2; if (url != null) { try { str10 = url.getHost(); j14 = j13; } catch (Exception e20) { e10 = e20; j10 = j13; z13 = z10; bufferedInputStream2 = bufferedInputStream5; z15 = z14; i11 = i14; str5 = str8; i10 = i16; str6 = str7; httpURLConnection2 = httpURLConnection5; j11 = j12; navigationClient.detectNaviIfNeed(navigationClient.context); writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th16) { z13 = z10; th2 = th16; i18 = i16; httpURLConnection6 = httpURLConnection5; bufferedInputStream = bufferedInputStream5; navigationClient.freeObject(z13, httpURLConnection6, bufferedInputStream, i18); throw th2; } } else { j14 = j13; str10 = str9; } instance.recordNavi(z16, str10, (int) j14); navigationClient.freeObject(z10, httpURLConnection5, bufferedInputStream5, i16); return z14; } catch (Exception e21) { e10 = e21; z13 = z10; long j15 = delta; httpURLConnection4 = httpURLConnection3; int i20 = responseCode; url = urlStr; j10 = j15; i10 = i20; bufferedInputStream2 = bufferedInputStream4; i11 = i14; str5 = str8; str6 = str7; j11 = j12; httpURLConnection2 = httpURLConnection4; navigationClient.detectNaviIfNeed(navigationClient.context); writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th17) { Throwable th18 = th17; z13 = z10; HttpURLConnection httpURLConnection7 = httpURLConnection3; int i21 = responseCode; httpURLConnection6 = httpURLConnection7; th2 = th18; bufferedInputStream = bufferedInputStream4; i18 = i21; navigationClient.freeObject(z13, httpURLConnection6, bufferedInputStream, i18); throw th2; } } catch (Exception e22) { e10 = e22; i13 = -1; bufferedInputStream3 = null; z13 = z10; url = urlStr; str6 = ""; str5 = str6; i11 = 0; i10 = i13; bufferedInputStream2 = bufferedInputStream3; httpURLConnection2 = bufferedInputStream2; j11 = -1; j10 = -1; navigationClient.detectNaviIfNeed(navigationClient.context); writeRequestExceptionLog(str, i10, url, str6, str5, j11, j10, i11, e10); navigationClient.observerError(z13, z11); navigationClient.recordNavi(url); navigationClient.freeObject(z13, httpURLConnection2, bufferedInputStream2, i10); return z15; } catch (Throwable th19) { BufferedInputStream bufferedInputStream8 = null; z13 = z10; th2 = th19; bufferedInputStream = bufferedInputStream8; httpURLConnection6 = bufferedInputStream; navigationClient.freeObject(z13, httpURLConnection6, bufferedInputStream, i18); throw th2; } } private void writeRequestExceptionLog(String str, int i10, URL url, String str2, String str3, long j10, long j11, int i11, Exception exc) { String str4; RLog.e(TAG, "request exception."); int i12 = 0; FwLog.write(1, 1, FwLog.LogTag.L_CRASH_IPC_EPT_F.getTag(), CrashConstant.CRASH_STACK_KEY, FwLog.stackToString(exc)); FwLog.write(3, 1, FwLog.LogTag.L_GET_NAVI_R.getTag(), "code|url", Integer.valueOf(i10), str); QAStatisticsHelper qAStatisticsHelper = QAStatisticsHelper.INSTANCE; if (url == null) { str4 = ""; } else { str4 = url.getHost(); } if (url != null) { i12 = url.getPort(); } qAStatisticsHelper.reqNaviComplete(str4, i12, str2, str3, i11, j10, i10, j11); } private void writeRequestLog(String str, String str2, String str3, boolean z10) { RLog.d(TAG, "[connect] request " + str + ", appKey:" + str2 + ", token: " + str3 + ", forceUpdate:" + z10); } public void addObserver(NavigationObserver navigationObserver) { if (navigationObserver != null && !this.navigationObservers.contains(navigationObserver)) { this.navigationObservers.add(navigationObserver); } } public void clearCacheTime(Context context2) { NavigationCacheHelper.updateTime(context2, 0); } 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 int getAlgorithm(Context context2) { return NavigationCacheHelper.getAlgorithm(context2); } public void getCMPServerString(Context context2, String str, String str2) { RLog.d(TAG, "[connect] getCMPServerString."); this.context = context2.getApplicationContext(); if (isNaviCacheValid(context2, str, str2)) { RLog.d(TAG, "[connect] cache is valid."); String userId = NavigationCacheHelper.getUserId(context2); QAStatisticsHelper.INSTANCE.reqNaviCompleteFromCache(); onNaviSuccess(userId); return; } String userId2 = NavigationCacheHelper.getUserId(context2); if (str2 == null || !str2.equals(NavigationCacheHelper.getToken(context2))) { NavigationCacheHelper.clearUserId(context2); RLog.d(TAG, "[connect] clear userId."); userId2 = ""; } if (!CMPStrategy.getInstance().getCmpList().isEmpty()) { RLog.d(TAG, "[connect] cache cmp length > 0."); QAStatisticsHelper.INSTANCE.reqNaviCompleteFromCache(); onNaviSuccess(userId2); return; } requestNavi(str, str2, true); } public int getGroupMessageLimit(Context context2) { return NavigationCacheHelper.getGroupMessageLimit(context2); } public String getKeyE(Context context2) { return NavigationCacheHelper.getKeyE(context2); } public String getKeyN(Context context2) { return NavigationCacheHelper.getKeyN(context2); } public String getMediaServer(Context context2) { return NavigationCacheHelper.getMediaServer(context2); } public List<FilePlatformInfo> getMediaServerConfigs(Context context2) { return NavigationCacheHelper.getMediaServerCache(context2); } public String getNavPreferenceValue(Context context2, String str) { return NavigationCacheHelper.getNavigationPreferenceValue(context2, str); } public String getNaviString() { return this.naviString; } public List<String> getNaviUrlList() { return this.naviUrlList; } public String getPrimeG(Context context2) { return NavigationCacheHelper.getPrimeG(context2); } public String getPrimeP(Context context2) { return NavigationCacheHelper.getPrimeP(context2); } public long getRandomR(Context context2) { return NavigationCacheHelper.getRandomR(context2); } public String getSite(Context context2) { return NavigationCacheHelper.getSite(context2); } 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 String getUploadLogConfigInfo(Context context2) { return NavigationCacheHelper.getRealTimeLogConfig(context2); } public String getUserId(Context context2) { return NavigationCacheHelper.getUserId(context2); } public String getVoIPCallInfo(Context context2) { return NavigationCacheHelper.getVoIPCallInfo(context2); } public void init(Context context2) { this.enableHttps = NetUtils.isHttpsEnable(context2); 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); } public boolean isChatroomHistoryEnabled(Context context2) { return NavigationCacheHelper.isChatroomHistoryEnabled(context2); } public boolean isFetching() { return this.fetching.get(); } public boolean isGROpened(Context context2) { return NavigationCacheHelper.isGetRemoteEnabled(context2); } public boolean isGetRemoteHistoryEnabled(Context context2) { return NavigationCacheHelper.isGetRemoteEnabled(context2); } public boolean isMPOpened(Context context2) { return NavigationCacheHelper.isMPOpened(context2); } public boolean isNaviCacheValid(Context context2, String str, String str2) { return NavigationCacheHelper.isCacheValid(context2, str, str2, this.naviString); } public boolean isRepairMsgEnabled(Context context2) { return NavigationCacheHelper.isRepairMsgEnabled(context2); } public boolean isUSOpened(Context context2) { return NavigationCacheHelper.isUSOpened(context2); } public boolean isUltraGroupEnabled(Context context2) { return NavigationCacheHelper.isUltraGroupEnabled(context2); } public void onNaviError(String str, int i10) { Iterator it2 = new ArrayList(this.navigationObservers).iterator(); while (it2.hasNext()) { ((NavigationObserver) it2.next()).onError(str, i10); } } public void onNaviSuccess(String str) { Iterator it2 = new ArrayList(this.navigationObservers).iterator(); while (it2.hasNext()) { ((NavigationObserver) it2.next()).onSuccess(str); } } public void onNaviUpdate(String str) { Iterator it2 = new ArrayList(this.navigationObservers).iterator(); while (it2.hasNext()) { ((NavigationObserver) it2.next()).onUpdate(str); } } public void requestCmpIfNeed(Context context2, String str, String str2) { if (NavigationCacheHelper.isCacheTimeout(context2)) { this.executor.execute(new a(this, str, str2)); } } public void requestNavi(String str, String str2, boolean z10) { this.executor.execute(new b(this, str2, str, z10)); } public void setNaviDomainList(String str) { this.naviString = str; List<String> list = this.naviUrlList; if (list != null) { list.clear(); if (str != null) { this.naviUrlList.addAll(naviStrToList(str, h.f134437b)); this.enableHttpDns = HttpDnsManager.getInstance().shouldEnableHttpDns(this.naviUrlList); } } } public void setNaviUpdateListener(NaviUpdateListener naviUpdateListener2) { this.naviUpdateListener = naviUpdateListener2; } private NavigationClient() { this.naviUrlList = new ArrayList(7); this.naviUpdateListener = null; this.navigationObservers = new ArrayList(); this.latestTokenNaviList = new ArrayList(7); this.fetching = new AtomicBoolean(false); this.enableHttps = true; this.enableHttpDns = false; this.enableHttpDnsRequest = false; this.executor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, new LinkedBlockingQueue(), ExecutorFactory.threadFactory(TAG)); } }