package d.f.a.r2;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.hardware.usb.UsbDevice;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import com.seewo.sdk.model.SDKKeyboardCode;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import jxl.SheetSettings;

/* JADX INFO: compiled from: XmlUtil.java */
/* JADX INFO: loaded from: classes.dex */
public class h3 {
    public static boolean a;

    public static String a(byte[] bArr) {
        if (bArr == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (byte b2 : bArr) {
            sb.append(String.format("0x%X ", Byte.valueOf(b2)));
        }
        return sb.toString();
    }

    public static String b(byte[] bArr, int i2, int i3) {
        if (bArr.length != 0 && i2 >= 0 && i3 > 0 && i2 < bArr.length && bArr.length - i2 >= i3) {
            byte[] bArr2 = new byte[i3];
            System.arraycopy(bArr, i2, bArr2, 0, i3);
            try {
                return new String(bArr2, "ISO8859-1");
            } catch (UnsupportedEncodingException e2) {
                Log.e("ByteUtils", e2.getMessage(), e2);
            }
        }
        return null;
    }

    public static String c(byte[] bArr) {
        char[] cArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
        char[] cArr2 = new char[bArr.length * 2];
        for (int i2 = 0; i2 < bArr.length; i2++) {
            byte b2 = bArr[i2];
            int i3 = i2 * 2;
            cArr2[i3] = cArr[(b2 >>> 4) & 15];
            cArr2[i3 + 1] = cArr[b2 & SDKKeyboardCode.FUNCTION_KEY_BOARD_L];
        }
        return new String(cArr2);
    }

    public static String d(byte[] bArr) {
        StringBuilder sb = new StringBuilder();
        for (byte b2 : bArr) {
            String hexString = Integer.toHexString(b2 & 255);
            sb.append("0x");
            if (hexString.length() == 1) {
                sb.append("0");
            }
            sb.append(hexString);
            sb.append(" ");
        }
        return sb.toString().toUpperCase();
    }

    public static String e(byte b2) {
        StringBuilder sb = new StringBuilder();
        String hexString = Integer.toHexString(b2 & 255);
        sb.append("0x");
        if (hexString.length() == 1) {
            sb.append("0");
        }
        sb.append(hexString);
        sb.append(" ");
        return sb.toString().toUpperCase();
    }

    public static void f(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        Log.d("UpgradeSDK", str);
        if (a) {
            d.f.f.f.c.b().c(str);
        }
    }

    public static void g(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        Log.e("UpgradeSDK", str);
        if (a) {
            d.f.f.f.c.b().c(str);
        }
    }

    public static void h(String str, Throwable th) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        Log.e("UpgradeSDK", str, th);
        if (a) {
            d.f.f.f.c.b().c(str);
        }
    }

    public static void i(Throwable th) {
        g(Log.getStackTraceString(th));
        if (a) {
            d.f.f.f.c.b().c(Log.getStackTraceString(th));
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:51:0x00b7  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00cd  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x00d5  */
    /* JADX WARN: Removed duplicated region for block: B:66:0x00eb A[Catch: IOException -> 0x00e7, TryCatch #3 {IOException -> 0x00e7, blocks: (B:62:0x00e3, B:66:0x00eb, B:68:0x00f0), top: B:74:0x00e3 }] */
    /* JADX WARN: Removed duplicated region for block: B:68:0x00f0 A[Catch: IOException -> 0x00e7, TRY_LEAVE, TryCatch #3 {IOException -> 0x00e7, blocks: (B:62:0x00e3, B:66:0x00eb, B:68:0x00f0), top: B:74:0x00e3 }] */
    /* JADX WARN: Removed duplicated region for block: B:74:0x00e3 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static d.f.f.f.e j(java.lang.String r12) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 248
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: d.f.a.r2.h3.j(java.lang.String):d.f.f.f.e");
    }

    public static byte k(byte[] bArr, int i2) {
        int i3 = 0;
        for (int i4 = 0; i4 < i2; i4++) {
            i3 += bArr[i4] & 255;
        }
        return (byte) ((i3 % 256) & SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT);
    }

    public static String l(StringBuilder sb) {
        String[] strArrSplit = sb.toString().split("\n");
        StringBuilder sb2 = new StringBuilder("");
        for (int i2 = 0; i2 < strArrSplit.length - 1; i2++) {
            sb2.append(strArrSplit[i2]);
            sb2.append('\n');
        }
        return sb2.toString();
    }

    public static String m(String str, String str2) {
        try {
            return (String) new d.f.f.f.d(Class.forName("android.os.SystemProperties")).a("get", str, str2).f3563b;
        } catch (Exception e2) {
            Log.e("", e2.getMessage(), e2);
            return str2;
        }
    }

    public static String n(Throwable th) {
        for (Throwable cause = th; cause != null; cause = cause.getCause()) {
            if (cause instanceof UnknownHostException) {
                return "";
            }
        }
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        th.printStackTrace(printWriter);
        printWriter.flush();
        return stringWriter.toString();
    }

    public static <T> T o(Class cls, String str, T t) {
        Field field;
        try {
            try {
                field = (Field) d.i.b.c.a.a(cls.getField(str));
            } catch (NoSuchFieldException e2) {
                Class superclass = cls;
                do {
                    try {
                        field = (Field) d.i.b.c.a.a(superclass.getDeclaredField(str));
                    } catch (NoSuchFieldException unused) {
                        superclass = superclass.getSuperclass();
                    }
                } while (superclass != null);
                throw new d.i.b.c.b(e2);
            }
            field.getType();
            return (T) field.get(cls);
        } catch (Exception e3) {
            try {
                throw new d.i.b.c.b(e3);
            } catch (d.i.b.c.b e4) {
                e4.printStackTrace();
                return t;
            }
        }
    }

    public static boolean p(UsbDevice usbDevice) {
        return d.f.f.f.b.g(usbDevice, 8183, 1282) || d.f.f.f.b.g(usbDevice, 7531, 258) || d.f.f.f.b.g(usbDevice, 8183, 1288) || d.f.f.f.b.g(usbDevice, 8183, 3919);
    }

    public static boolean q(String str) {
        return str == null || str.trim().length() == 0;
    }

    public static String r(String[] strArr, String str) {
        String string = "";
        for (int i2 = 0; i2 < strArr.length; i2++) {
            StringBuilder sbB = d.b.a.a.a.B(string);
            sbB.append(strArr[i2]);
            string = sbB.toString();
            if (i2 < strArr.length - 1) {
                string = d.b.a.a.a.p(string, str);
            }
        }
        return string;
    }

    public static void s(Context context, Throwable th) {
        TreeMap treeMap = new TreeMap();
        try {
            treeMap.put("systemVersion", Build.VERSION.RELEASE);
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 1);
            if (packageInfo != null) {
                String str = packageInfo.versionName;
                if (str == null) {
                    str = "null";
                }
                String str2 = packageInfo.versionCode + "";
                treeMap.put("versionName", str);
                treeMap.put("versionCode", str2);
            }
        } catch (PackageManager.NameNotFoundException unused) {
        }
        for (Field field : Build.class.getDeclaredFields()) {
            try {
                field.setAccessible(true);
                treeMap.put(field.getName(), field.get(null).toString());
            } catch (Exception unused2) {
            }
        }
        StringBuilder sb = new StringBuilder();
        for (Map.Entry entry : treeMap.entrySet()) {
            String str3 = (String) entry.getKey();
            String str4 = (String) entry.getValue();
            sb.append(str3);
            sb.append("=");
            sb.append(str4);
            sb.append("\n");
        }
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        th.printStackTrace(printWriter);
        for (Throwable cause = th.getCause(); cause != null; cause = cause.getCause()) {
            cause.printStackTrace(printWriter);
        }
        printWriter.close();
        sb.append(stringWriter.toString());
        try {
            String str5 = "crash-" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + "-" + System.currentTimeMillis() + ".log";
            StringBuilder sb2 = new StringBuilder();
            sb2.append(context.getCacheDir().getPath());
            String str6 = File.separator;
            sb2.append(str6);
            sb2.append("crash");
            sb2.append(str6);
            String string = sb2.toString();
            new File(string).mkdirs();
            FileOutputStream fileOutputStream = new FileOutputStream(string + str5);
            fileOutputStream.write(sb.toString().getBytes());
            fileOutputStream.close();
        } catch (Exception unused3) {
        }
    }

    public static void t(String str, String str2) {
        try {
            new d.f.f.f.d(Class.forName("android.os.SystemProperties")).a("set", str, str2);
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }
}
