小红书.apk(点击下载) / c.java


package com.baidu.mapsdkplatform.comapi.b.a;

import android.content.Context;
import android.os.Build;
import com.ali.auth.third.login.LoginConstants;
import com.baidu.mapapi.NetworkUtil;
import com.baidu.mapsdkplatform.comapi.util.SyncSysInfo;
import com.baidu.mapsdkplatform.comapi.util.h;
import com.baidu.mapsdkplatform.comapi.util.i;
import com.baidu.mapsdkplatform.comjni.util.JNIHandler;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.util.zip.GZIPOutputStream;
import org.cybergarage.http.HTTP;
import org.json.JSONObject;

public class c {

    /* renamed from: a  reason: collision with root package name */
    private static String f20235a = "";

    /* renamed from: b  reason: collision with root package name */
    private static String f20236b = "";

    /* renamed from: c  reason: collision with root package name */
    private static String f20237c = "";

    /* renamed from: d  reason: collision with root package name */
    private Context f20238d;

    public static final class a {

        /* renamed from: a  reason: collision with root package name */
        private static final c f20239a = new c();
    }

    public static c a() {
        return a.f20239a;
    }

    private void a(InputStream inputStream, OutputStream outputStream) throws Exception {
        GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(outputStream);
        byte[] bArr = new byte[1024];
        while (true) {
            int read = inputStream.read(bArr, 0, 1024);
            if (read != -1) {
                gZIPOutputStream.write(bArr, 0, read);
            } else {
                gZIPOutputStream.flush();
                gZIPOutputStream.close();
                try {
                    outputStream.close();
                    inputStream.close();
                    return;
                } catch (Exception unused) {
                    return;
                }
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void a(File[] fileArr) {
        int length = fileArr.length;
        for (int i10 = 0; i10 < length - 10; i10++) {
            int i14 = i10 + 10;
            if (fileArr[i14] != null && fileArr[i14].exists()) {
                fileArr[i14].delete();
            }
        }
    }

    /* JADX DEBUG: Failed to insert an additional move for type inference into block B:64:? */
    /* access modifiers changed from: private */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r5v0, types: [java.io.BufferedReader] */
    /* JADX WARN: Type inference failed for: r5v1 */
    /* JADX WARN: Type inference failed for: r5v2, types: [java.io.BufferedReader] */
    /* JADX WARN: Type inference failed for: r5v3 */
    /* access modifiers changed from: public */
    /* JADX WARNING: Can't wrap try/catch for region: R(14:11|12|13|14|(2:15|(1:17)(1:107))|18|(11:20|21|22|23|24|(2:25|(1:27)(1:108))|28|29|30|(1:36)|37)(1:44)|(2:45|46)|(2:50|51)|52|53|54|56|57) */
    /* JADX WARNING: Code restructure failed: missing block: B:39:0x00e0, code lost:
        r10 = th;
        r5 = r5;
     */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:52:0x00f7 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:84:0x0127 */
    /* JADX WARNING: Removed duplicated region for block: B:100:0x0142 A[SYNTHETIC, Splitter:B:100:0x0142] */
    /* JADX WARNING: Removed duplicated region for block: B:39:0x00e0 A[ExcHandler: all (th java.lang.Throwable), Splitter:B:23:0x00ac] */
    /* JADX WARNING: Removed duplicated region for block: B:73:0x0111 A[SYNTHETIC, Splitter:B:73:0x0111] */
    /* JADX WARNING: Removed duplicated region for block: B:82:0x0124 A[SYNTHETIC, Splitter:B:82:0x0124] */
    /* JADX WARNING: Removed duplicated region for block: B:90:0x012d A[SYNTHETIC, Splitter:B:90:0x012d] */
    private synchronized boolean a(File file) {
        BufferedReader bufferedReader;
        InputStream inputStream;
        HttpURLConnection httpURLConnection;
        Throwable th3;
        BufferedReader bufferedReader2;
        BufferedReader bufferedReader3;
        BufferedReader bufferedReader4;
        OutputStream outputStream = null;
        BufferedReader bufferedReader5 = null;
        OutputStream outputStream2 = null;
        try {
            httpURLConnection = g();
            if (httpURLConnection == null) {
                if (httpURLConnection != null) {
                    try {
                        httpURLConnection.disconnect();
                    } catch (Exception unused) {
                    }
                }
                return false;
            }
            try {
                httpURLConnection.connect();
                OutputStream outputStream3 = httpURLConnection.getOutputStream();
                try {
                    outputStream3.write(a(b(file).toString().getBytes()));
                    outputStream3.write(a(("--bd_map_sdk_cc" + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"c.txt\"\r\n" + "\r\n").getBytes()));
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream((int) file.length());
                    DataInputStream dataInputStream = new DataInputStream(new FileInputStream(file));
                    byte[] bArr = new byte[1024];
                    while (true) {
                        int read = dataInputStream.read(bArr);
                        if (read == -1) {
                            break;
                        }
                        byteArrayOutputStream.write(bArr, 0, read);
                    }
                    outputStream3.write(a(byteArrayOutputStream.toByteArray()));
                    dataInputStream.close();
                    byteArrayOutputStream.close();
                    outputStream3.write(a("\r\n--bd_map_sdk_cc--\r\n".getBytes()));
                    outputStream3.flush();
                    if (httpURLConnection.getResponseCode() == 200) {
                        inputStream = httpURLConnection.getInputStream();
                        try {
                            bufferedReader3 = new BufferedReader(new InputStreamReader(inputStream));
                            try {
                                StringBuffer stringBuffer = new StringBuffer();
                                while (true) {
                                    int read2 = bufferedReader3.read();
                                    if (read2 == -1) {
                                        break;
                                    }
                                    stringBuffer.append((char) read2);
                                }
                                JSONObject jSONObject = new JSONObject(stringBuffer.toString());
                                if (jSONObject.has("status") && jSONObject.getInt("status") == 0 && file.exists()) {
                                    file.delete();
                                }
                            } catch (Exception unused2) {
                            } catch (Throwable th4) {
                            }
                            bufferedReader5 = bufferedReader3;
                        } catch (Exception unused3) {
                            bufferedReader3 = null;
                            outputStream = outputStream3;
                            bufferedReader = bufferedReader3;
                            if (outputStream != null) {
                            }
                            try {
                                inputStream.close();
                                bufferedReader.close();
                            } catch (Exception unused4) {
                            }
                            if (httpURLConnection != null) {
                            }
                            return false;
                        } catch (Throwable th5) {
                            th3 = th5;
                            bufferedReader4 = null;
                            outputStream2 = outputStream3;
                            bufferedReader2 = bufferedReader4;
                            if (outputStream2 != null) {
                            }
                            try {
                                inputStream.close();
                                bufferedReader2.close();
                            } catch (Exception unused5) {
                            }
                            if (httpURLConnection != null) {
                            }
                            throw th3;
                        }
                    } else {
                        inputStream = null;
                    }
                    try {
                        outputStream3.close();
                    } catch (Exception unused6) {
                    }
                    if (!(inputStream == null || bufferedReader5 == null)) {
                        inputStream.close();
                        bufferedReader5.close();
                    }
                    httpURLConnection.disconnect();
                    return true;
                } catch (Exception unused7) {
                    inputStream = null;
                    bufferedReader3 = null;
                    outputStream = outputStream3;
                    bufferedReader = bufferedReader3;
                    if (outputStream != null) {
                        try {
                            outputStream.close();
                        } catch (Exception unused8) {
                        }
                    }
                    if (!(inputStream == null || bufferedReader == 0)) {
                        inputStream.close();
                        bufferedReader.close();
                    }
                    if (httpURLConnection != null) {
                        try {
                            httpURLConnection.disconnect();
                        } catch (Exception unused9) {
                        }
                    }
                    return false;
                } catch (Throwable th6) {
                    th3 = th6;
                    inputStream = null;
                    bufferedReader4 = null;
                    outputStream2 = outputStream3;
                    bufferedReader2 = bufferedReader4;
                    if (outputStream2 != null) {
                        try {
                            outputStream2.close();
                        } catch (Exception unused10) {
                        }
                    }
                    if (!(inputStream == null || bufferedReader2 == 0)) {
                        inputStream.close();
                        bufferedReader2.close();
                    }
                    if (httpURLConnection != null) {
                        httpURLConnection.disconnect();
                    }
                    throw th3;
                }
            } catch (Exception unused11) {
                inputStream = null;
                bufferedReader = inputStream;
                if (outputStream != null) {
                }
                inputStream.close();
                bufferedReader.close();
                if (httpURLConnection != null) {
                }
                return false;
            } catch (Throwable th7) {
                th3 = th7;
                inputStream = null;
                bufferedReader2 = inputStream;
                if (outputStream2 != null) {
                }
                inputStream.close();
                bufferedReader2.close();
                if (httpURLConnection != null) {
                }
                throw th3;
            }
        } catch (Exception unused12) {
            httpURLConnection = null;
            inputStream = null;
            bufferedReader = inputStream;
            if (outputStream != null) {
            }
            inputStream.close();
            bufferedReader.close();
            if (httpURLConnection != null) {
            }
            return false;
        } catch (Throwable th8) {
            th3 = th8;
            httpURLConnection = null;
            inputStream = null;
            bufferedReader2 = inputStream;
            if (outputStream2 != null) {
            }
            inputStream.close();
            bufferedReader2.close();
            if (httpURLConnection != null) {
            }
            throw th3;
        }
    }

    private byte[] a(byte[] bArr) throws Exception {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bArr);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(bArr.length);
        a(byteArrayInputStream, byteArrayOutputStream);
        byte[] byteArray = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.flush();
        byteArrayOutputStream.close();
        byteArrayInputStream.close();
        return byteArray;
    }

    private StringBuilder b(File file) {
        String[] split = file.getName().substring(0, file.getName().length() - 4).split(LoginConstants.UNDER_LINE);
        StringBuilder sb3 = new StringBuilder();
        sb3.append("--bd_map_sdk_cc");
        sb3.append("\r\n");
        sb3.append("Content-Disposition: form-data; name=\"phoneinfo\"\r\n");
        sb3.append("\r\n");
        sb3.append(URLDecoder.decode(SyncSysInfo.getPhoneInfo() + "&abi=" + f20237c));
        sb3.append("\r\n");
        sb3.append("--bd_map_sdk_cc");
        sb3.append("\r\n");
        if (split[0] != null && !split[0].isEmpty()) {
            sb3.append("Content-Disposition: form-data; name=\"packname\"\r\n");
            sb3.append("\r\n");
            sb3.append(split[0]);
            sb3.append("\r\n");
            sb3.append("--bd_map_sdk_cc");
            sb3.append("\r\n");
        }
        if (split[1] != null && !split[1].isEmpty()) {
            sb3.append("Content-Disposition: form-data; name=\"version\"\r\n");
            sb3.append("\r\n");
            sb3.append(split[1]);
            sb3.append("\r\n");
            sb3.append("--bd_map_sdk_cc");
            sb3.append("\r\n");
        }
        if (split[2] != null && !split[2].isEmpty()) {
            sb3.append("Content-Disposition: form-data; name=\"timestamp\"\r\n");
            sb3.append("\r\n");
            sb3.append(split[2]);
            sb3.append("\r\n");
            sb3.append("--bd_map_sdk_cc");
            sb3.append("\r\n");
        }
        sb3.append("Content-Disposition: form-data; name=\"os\"\r\n");
        sb3.append("\r\n");
        sb3.append("android");
        sb3.append("\r\n");
        sb3.append("--bd_map_sdk_cc");
        sb3.append("\r\n");
        return sb3;
    }

    private void d() {
        if (h.a().b() != null) {
            String b14 = h.a().b().b();
            if (!b14.isEmpty()) {
                String str = b14 + File.separator + "crash";
                File file = new File(str);
                if (!file.exists() && !file.mkdir()) {
                    f20235a = b14;
                } else {
                    f20235a = str;
                }
            }
        }
    }

    private void e() {
        String str;
        String str2 = f20235a;
        if (str2 != null && !str2.isEmpty() && (str = f20236b) != null && !str.isEmpty()) {
            String str3 = f20235a + File.separator + f20236b;
            a.a().a(str3);
            JNIHandler.registerNativeHandler(str3);
        }
    }

    private void f() {
        if (NetworkUtil.isNetworkAvailable(this.f20238d)) {
            new Thread(new d(this)).start();
        }
    }

    private HttpURLConnection g() {
        try {
            HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("https://api.map.baidu.com/lbs_sdkcc/report").openConnection();
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setUseCaches(false);
            httpURLConnection.setRequestMethod("POST");
            httpURLConnection.setRequestProperty("Connection", "keep-alive");
            httpURLConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=bd_map_sdk_cc");
            httpURLConnection.setRequestProperty("Cache-Control", HTTP.NO_CACHE);
            httpURLConnection.setRequestProperty("Content-Encoding", "gzip");
            httpURLConnection.setConnectTimeout(10000);
            return httpURLConnection;
        } catch (Exception unused) {
            return null;
        }
    }

    public void a(Context context) {
        if (Build.VERSION.SDK_INT >= 21) {
            String[] strArr = Build.SUPPORTED_ABIS;
            if (strArr.length > 0) {
                f20237c = strArr[0];
            }
            this.f20238d = context;
            String n14 = i.n();
            if (!n14.isEmpty()) {
                if (n14.contains(LoginConstants.UNDER_LINE)) {
                    n14 = n14.replaceAll(LoginConstants.UNDER_LINE, "");
                }
                f20236b = n14 + LoginConstants.UNDER_LINE + i.i() + LoginConstants.UNDER_LINE;
                d();
                e();
                f();
            }
        }
    }
}