package com.tencent.bugly.proguard; import android.util.Pair; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.HashMap; import java.util.List; import java.util.Map; import org.json.JSONArray; import org.json.JSONObject; public final class r { public final Pair<Integer, String> a(List<String> list) { try { HashMap hashMap = new HashMap(); hashMap.put("Atta-Type", "batch-report"); JSONObject jSONObject = new JSONObject(); jSONObject.put("attaid", "0d000062340").put("token", "2273782735").put("type", "batch").put("version", "v1.0.0"); JSONArray jSONArray = new JSONArray(); for (String str : list) { jSONArray.put(str); } jSONObject.put("datas", jSONArray); return a("https://h.trace.qq.com/kv", jSONObject.toString(), hashMap); } catch (Throwable th) { y.b(th); return new Pair<>(-1, th.getMessage()); } } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r9v2, types: [java.net.HttpURLConnection] */ /* JADX WARN: Type inference failed for: r9v4 */ /* JADX WARN: Type inference failed for: r9v7, types: [java.io.DataOutputStream] */ /* JADX WARNING: Removed duplicated region for block: B:36:0x00ae A[SYNTHETIC, Splitter:B:36:0x00ae] */ /* JADX WARNING: Removed duplicated region for block: B:41:0x00b9 A[SYNTHETIC, Splitter:B:41:0x00b9] */ /* JADX WARNING: Removed duplicated region for block: B:46:0x00c3 A[DONT_GENERATE] */ /* JADX WARNING: Unknown variable types count: 1 */ private Pair<Integer, String> a(String str, String str2, Map<String, String> map) { String str3; HttpURLConnection httpURLConnection; Throwable th; InputStream inputStream; byte[] bytes; ?? dataOutputStream; InputStream inputStream2; InputStream inputStream3 = null; int i = -1; try { HttpURLConnection httpURLConnection2 = (HttpURLConnection) new URL(str).openConnection(); try { httpURLConnection2.setRequestMethod("POST"); httpURLConnection2.setDoOutput(true); httpURLConnection2.setDoInput(true); httpURLConnection2.setUseCaches(false); httpURLConnection2.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); a(httpURLConnection2, map); httpURLConnection2.setConnectTimeout(5000); httpURLConnection2.setReadTimeout(5000); httpURLConnection2.connect(); bytes = str2.getBytes("UTF-8"); dataOutputStream = new DataOutputStream(httpURLConnection2.getOutputStream()); } catch (Throwable th2) { th = th2; httpURLConnection = httpURLConnection2; inputStream = inputStream3; try { y.b(th); str3 = th.getMessage(); return new Pair<>(Integer.valueOf(i), str3); } finally { if (inputStream3 != null) { try { inputStream3.close(); } catch (Exception e) { y.b(e); } } if (inputStream != null) { try { inputStream.close(); } catch (Exception e2) { y.b(e2); } } if (httpURLConnection != 0) { httpURLConnection.disconnect(); } } } try { dataOutputStream.write(bytes); dataOutputStream.flush(); dataOutputStream.close(); i = httpURLConnection2.getResponseCode(); if (i >= 400) { inputStream2 = httpURLConnection2.getErrorStream(); } else { inputStream2 = httpURLConnection2.getInputStream(); } try { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream2, "UTF-8")); StringBuilder sb = new StringBuilder(); while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } sb.append(readLine); sb.append("\r\n"); } bufferedReader.close(); str3 = sb.toString(); if (inputStream2 != null) { try { inputStream2.close(); } catch (Exception e3) { y.b(e3); } } if (httpURLConnection2 != null) { httpURLConnection2.disconnect(); } } catch (Throwable th3) { httpURLConnection = httpURLConnection2; inputStream = inputStream2; th = th3; y.b(th); str3 = th.getMessage(); return new Pair<>(Integer.valueOf(i), str3); } } catch (Throwable th4) { th = th4; httpURLConnection = httpURLConnection2; inputStream = inputStream3; inputStream3 = dataOutputStream; y.b(th); str3 = th.getMessage(); return new Pair<>(Integer.valueOf(i), str3); } } catch (Throwable th5) { th = th5; inputStream = inputStream3; httpURLConnection = inputStream; y.b(th); str3 = th.getMessage(); return new Pair<>(Integer.valueOf(i), str3); } return new Pair<>(Integer.valueOf(i), str3); } private static void a(HttpURLConnection httpURLConnection, Map<String, String> map) { if (!(httpURLConnection == null || map == null || map.isEmpty())) { for (Map.Entry<String, String> entry : map.entrySet()) { httpURLConnection.setRequestProperty(entry.getKey(), entry.getValue()); } } } }