得物.apk(点击下载) / es.java


package c.t.m.g;

import a.f;
import a30.h;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import androidx.core.view.accessibility.AccessibilityEventCompat;
import h.b;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

/* compiled from: TML */
public class es {

    /* renamed from: a  reason: collision with root package name */
    private String f2211a = "es";
    private Context b;

    /* renamed from: c  reason: collision with root package name */
    private fh f2212c;
    private SimpleDateFormat d = new SimpleDateFormat("HHmmss");
    private a e;
    private StringBuilder f;

    /* renamed from: g  reason: collision with root package name */
    private String f2213g = "d";

    /* renamed from: h  reason: collision with root package name */
    private File f2214h = null;
    private String i;

    public es(Context context, Looper looper) {
        this.b = context;
        this.e = new a(looper);
        a();
    }

    public void b() {
        fc.a(this.e, 10004);
    }

    public void c() {
        fc.a(this.e, 10003);
    }

    public void a() {
        File file;
        File file2 = null;
        try {
            File file3 = new File(this.b.getExternalFilesDir("data").getAbsolutePath() + File.separator + "TMLSDK");
            if (!file3.exists()) {
                file3.mkdirs();
            }
            file = file3;
        } catch (Throwable unused) {
            file = null;
        }
        this.f2214h = file;
        if (file != null) {
            file2 = new File(file, this.f2213g);
        }
        this.i = "d_";
        this.f2212c = new fh(this.b, file, file2, "d", 20480);
        fc.a(this.e, 10004, 60000);
    }

    public void a(String str, String str2) {
        String str3;
        String str4 = "--";
        try {
            str3 = Thread.currentThread().getName();
            try {
                str4 = fk.d(this.b);
            } catch (Throwable unused) {
            }
        } catch (Throwable unused2) {
            str3 = str4;
        }
        StringBuilder sb2 = new StringBuilder();
        sb2.append(this.d.format(new Date()));
        sb2.append(",");
        sb2.append(str4);
        sb2.append(",");
        b.u(sb2, str3, ",", str, ",");
        sb2.append(str2);
        fc.a(this.e, 10001, 0, 0, sb2.toString());
    }

    public void a(String str, int i3) {
        fc.a(this.e, 10013, i3, 0, str);
    }

    public boolean a(byte[] bArr) {
        if (bArr != null) {
            try {
                if (bArr.length != 0) {
                    byte[] a5 = fk.a(bArr, fk.a("m_log_key", fg.p));
                    if (a5 != null) {
                        if (a5.length != 0) {
                            if (ey.f2232a) {
                                String str = this.f2211a;
                                ey.a(str, "encData size:" + a5.length);
                            }
                            byte[] a12 = fd.a("https://analytics.map.qq.com/tr?mllc", a5);
                            if (a12 == null) {
                                if (ey.f2232a) {
                                    ey.b(this.f2211a, "upload buffer faild");
                                }
                                this.f2212c.a(a5);
                            } else if (ey.f2232a) {
                                String str2 = this.f2211a;
                                ey.b(str2, "upload buffer result:" + new String(a12));
                            }
                            return false;
                        }
                    }
                    if (ey.f2232a) {
                        ey.a(this.f2211a, "upload data enc is null");
                    }
                    return true;
                }
            } catch (Throwable th2) {
                if (ey.f2232a) {
                    ey.a(this.f2211a, "upload exception", th2);
                }
                return false;
            }
        }
        if (ey.f2232a) {
            ey.a(this.f2211a, "upload data is null");
        }
        return true;
    }

    /* compiled from: TML */
    public class a extends Handler {
        public a(Looper looper) {
            super(looper);
            es.this.f = new StringBuilder((int) AccessibilityEventCompat.TYPE_TOUCH_EXPLORATION_GESTURE_END);
        }

        public void a(Message message) {
            int i = message.what;
            if (i == 10001) {
                String str = (String) message.obj;
                if (ey.f2232a) {
                    h.m("writeCoreLog:", str, es.this.f2211a);
                }
                a(str);
            } else if (i == 10013) {
                String str2 = (String) message.obj;
                if (ey.f2232a) {
                    String str3 = es.this.f2211a;
                    ey.b(str3, "catched crash : " + str2);
                }
                es.this.a(str2.getBytes());
            } else if (i != 10003) {
                if (i == 10004) {
                    a();
                    fc.a(es.this.e, 10004, 60000);
                }
            } else if (es.this.f != null && es.this.f.length() > 0) {
                es.this.f.insert(0, fk.c(es.this.b, "COMP"));
                String sb2 = es.this.f.toString();
                if (ey.f2232a) {
                    h.m("uploadCorelog:", sb2, es.this.f2211a);
                }
                es.this.a(sb2.getBytes());
                es.this.f.setLength(0);
            }
        }

        public void handleMessage(Message message) {
            try {
                a(message);
            } catch (Throwable th2) {
                th2.printStackTrace();
            }
        }

        private void a(String str) {
            StringBuilder sb2 = es.this.f;
            sb2.append(str);
            sb2.append("$");
        }

        private void a() {
            File[] listFiles;
            File file = es.this.f2214h;
            if (file != null && file.exists() && file.isDirectory() && (listFiles = file.listFiles()) != null && listFiles.length > 0) {
                for (File file2 : listFiles) {
                    if (file2.exists() && file2.getName().startsWith(es.this.i)) {
                        byte[] a5 = a(file2);
                        if (a5 != null && a5.length > 0) {
                            byte[] a12 = fd.a("https://analytics.map.qq.com/tr?mllc", a5);
                            if (a12 != null) {
                                if (ey.f2232a) {
                                    String str = es.this.f2211a;
                                    StringBuilder h12 = f.h("upload files success :");
                                    h12.append(new String(a12));
                                    ey.b(str, h12.toString());
                                }
                                file2.delete();
                            }
                        } else if (a5 != null && a5.length == 0) {
                            file2.delete();
                        }
                    }
                }
            }
        }

        /* JADX WARNING: Can't wrap try/catch for region: R(7:16|15|17|18|19|13|14) */
        /* JADX WARNING: Code restructure failed: missing block: B:20:0x0043, code lost:
            r7 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:21:0x0044, code lost:
            a(r2);
            a(r0);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:22:0x004a, code lost:
            throw r7;
         */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:17:0x003d */
        private byte[] a(File file) {
            byte[] bArr;
            if (!file.exists() || file.length() == 0) {
                return new byte[0];
            }
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            Closeable closeable = null;
            byte[] bArr2 = new byte[AccessibilityEventCompat.TYPE_VIEW_SCROLLED];
            BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
            while (true) {
                try {
                    int read = bufferedInputStream.read(bArr2);
                    if (read == -1) {
                        break;
                    }
                    byteArrayOutputStream.write(bArr2, 0, read);
                } catch (Throwable unused) {
                    closeable = bufferedInputStream;
                    bArr = new byte[0];
                    a(closeable);
                    a(byteArrayOutputStream);
                    return bArr;
                }
            }
            bArr = byteArrayOutputStream.toByteArray();
            a(bufferedInputStream);
            a(byteArrayOutputStream);
            return bArr;
        }

        private void a(Closeable closeable) {
            if (closeable != null) {
                try {
                    closeable.close();
                } catch (Throwable unused) {
                }
            }
        }
    }
}