package com.seewo.libshid.util;

import android.util.Log;
import com.seewo.vcommons.utils.ShellCommandUtils;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.Thread;

/* JADX INFO: loaded from: classes.dex */
public class BaseThread extends Thread {
    private static final String TAG = "BaseThread";
    public Thread mCurrentThread;
    public boolean mIsRunning;

    public BaseThread() {
        setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { // from class: com.seewo.libshid.util.BaseThread.1
            @Override // java.lang.Thread.UncaughtExceptionHandler
            public void uncaughtException(Thread thread, Throwable th) {
                Log.e(BaseThread.TAG, String.format("Got uncaughtException: thread id=[%d], name=[%s], msg=%s", Long.valueOf(BaseThread.this.getId()), BaseThread.this.getName(), BaseThread.this.getCrashInfo(th)));
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public String getCrashInfo(Throwable th) {
        StringBuilder sb = new StringBuilder();
        sb.append(th.getMessage() + ShellCommandUtils.COMMAND_LINE_END);
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        do {
            th.printStackTrace(printWriter);
            th = th.getCause();
        } while (th != null);
        sb.append(stringWriter.toString());
        printWriter.close();
        return sb.toString();
    }

    public boolean isRunning() {
        return this.mIsRunning && this.mCurrentThread.isAlive();
    }

    @Override // java.lang.Thread, java.lang.Runnable
    public void run() {
        this.mIsRunning = true;
        this.mCurrentThread = Thread.currentThread();
    }

    public void stopThread() {
        Log.v(TAG, "stopThread");
        this.mIsRunning = false;
        Thread thread = this.mCurrentThread;
        if (thread != null) {
            thread.interrupt();
            this.mCurrentThread = null;
        }
    }
}
