mirror of
https://github.com/KokaKiwi/BarInsta
synced 2026-03-04 11:31:35 +00:00
init
This commit is contained in:
commit
13beabf741
275 changed files with 22638 additions and 0 deletions
197
app/src/main/java/awaisomereport/CrashReporter.java
Executable file
197
app/src/main/java/awaisomereport/CrashReporter.java
Executable file
|
|
@ -0,0 +1,197 @@
|
|||
package awaisomereport;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Process;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Date;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import awais.instagrabber.BuildConfig;
|
||||
import awais.instagrabber.utils.Utils;
|
||||
|
||||
public final class CrashReporter implements Thread.UncaughtExceptionHandler {
|
||||
private static CrashReporter reporterInstance;
|
||||
private final Application application;
|
||||
private final String email;
|
||||
private final File crashLogsZip;
|
||||
private boolean startAttempted = false;
|
||||
|
||||
public static CrashReporter get(final Application application) {
|
||||
if (reporterInstance == null) reporterInstance = new CrashReporter(application);
|
||||
return reporterInstance;
|
||||
}
|
||||
|
||||
private CrashReporter(@NonNull final Application application) {
|
||||
this.application = application;
|
||||
// set your email(s) here to receive crash reports
|
||||
// this.email = "<email>";
|
||||
this.email = "chapter50000@hotmail.com";
|
||||
this.crashLogsZip = new File(application.getExternalCacheDir(), "crash_logs.zip");
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (!startAttempted) {
|
||||
Thread.setDefaultUncaughtExceptionHandler(this);
|
||||
startAttempted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncaughtException(@NonNull final Thread t, @NonNull final Throwable exception) {
|
||||
final StringBuilder reportBuilder = new StringBuilder();
|
||||
reportBuilder.append("Error report collected on: ").append(new Date().toString());
|
||||
reportBuilder.append("\r\n\r\nInformation:\r\n==============");
|
||||
|
||||
reportBuilder
|
||||
.append("\r\nVERSION : ").append(BuildConfig.VERSION_NAME)
|
||||
.append("\r\nVERSION_CODE : ").append(BuildConfig.VERSION_CODE)
|
||||
.append("\r\nPHONE-MODEL : ").append(Build.MODEL)
|
||||
.append("\r\nANDROID_VERS : ").append(Build.VERSION.RELEASE)
|
||||
.append("\r\nANDROID_REL : ").append(Build.VERSION.SDK_INT)
|
||||
.append("\r\nBRAND : ").append(Build.BRAND)
|
||||
.append("\r\nMANUFACTURER : ").append(Build.MANUFACTURER)
|
||||
.append("\r\nBOARD : ").append(Build.BOARD)
|
||||
.append("\r\nDEVICE : ").append(Build.DEVICE)
|
||||
.append("\r\nPRODUCT : ").append(Build.PRODUCT)
|
||||
.append("\r\nHOST : ").append(Build.HOST)
|
||||
.append("\r\nTAGS : ").append(Build.TAGS);
|
||||
|
||||
reportBuilder.append("\r\n\r\nStack:\r\n==============\r\n");
|
||||
final Writer result = new StringWriter();
|
||||
try (final PrintWriter printWriter = new PrintWriter(result)) {
|
||||
exception.printStackTrace(printWriter);
|
||||
reportBuilder.append(result.toString());
|
||||
|
||||
reportBuilder.append("\r\nCause:\r\n==============");
|
||||
|
||||
// for AsyncTask crashes
|
||||
Throwable cause = exception.getCause();
|
||||
while (cause != null) {
|
||||
cause.printStackTrace(printWriter);
|
||||
reportBuilder.append(result.toString());
|
||||
cause = cause.getCause();
|
||||
}
|
||||
}
|
||||
reportBuilder.append("\r\n\r\n**** End of current Report ***");
|
||||
|
||||
final String errorContent = reportBuilder.toString();
|
||||
try (final FileOutputStream trace = application.openFileOutput("stack-" + System.currentTimeMillis() + ".stacktrace", Context.MODE_PRIVATE)) {
|
||||
trace.write(errorContent.getBytes());
|
||||
} catch (final Exception ex) {
|
||||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", ex);
|
||||
}
|
||||
|
||||
application.startActivity(new Intent(application, ErrorReporterActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
|
||||
zipLogs();
|
||||
|
||||
Process.killProcess(Process.myPid());
|
||||
System.exit(10);
|
||||
}
|
||||
|
||||
public synchronized CrashReporter zipLogs() {
|
||||
final File logDir = Utils.logCollector != null ? Utils.logCollector.getLogDir() :
|
||||
new File(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? application.getDataDir() : application.getFilesDir(), "ur_mom_gay_logs");
|
||||
|
||||
try (final FileOutputStream fos = new FileOutputStream(crashLogsZip);
|
||||
final ZipOutputStream zos = new ZipOutputStream(fos)) {
|
||||
|
||||
final File[] files = logDir.listFiles();
|
||||
|
||||
if (files != null) {
|
||||
zos.setLevel(5);
|
||||
byte[] buffer;
|
||||
for (final File file : files) {
|
||||
if (file != null && file.length() > 0) {
|
||||
buffer = new byte[1024];
|
||||
try (final FileInputStream fis = new FileInputStream(file)) {
|
||||
zos.putNextEntry(new ZipEntry(file.getName()));
|
||||
int length;
|
||||
while ((length = fis.read(buffer)) > 0) zos.write(buffer, 0, length);
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (final Exception e) {
|
||||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public void startCrashEmailIntent(final Context context, final boolean sendZipsOnly) {
|
||||
try {
|
||||
final String filePath = context.getFilesDir().getAbsolutePath();
|
||||
|
||||
String[] errorFileList;
|
||||
|
||||
if (sendZipsOnly) errorFileList = null;
|
||||
else {
|
||||
try {
|
||||
final File dir = new File(filePath);
|
||||
if (dir.exists() && !dir.isDirectory()) dir.delete();
|
||||
dir.mkdir();
|
||||
errorFileList = dir.list((d, name) -> name.endsWith(".stacktrace"));
|
||||
} catch (final Exception e) {
|
||||
errorFileList = null;
|
||||
}
|
||||
}
|
||||
|
||||
if ((errorFileList != null && errorFileList.length > 0) || sendZipsOnly) {
|
||||
final StringBuilder errorStringBuilder;
|
||||
|
||||
if (sendZipsOnly) errorStringBuilder = new StringBuilder("So... what happened?\n\n");
|
||||
else {
|
||||
errorStringBuilder = new StringBuilder("\r\n\r\n");
|
||||
final int maxSendMail = 5;
|
||||
|
||||
int curIndex = 0;
|
||||
for (final String curString : errorFileList) {
|
||||
final File file = new File(filePath + '/' + curString);
|
||||
|
||||
if (curIndex++ <= maxSendMail) {
|
||||
errorStringBuilder.append("New Trace collected:\r\n=====================\r\n");
|
||||
try (final BufferedReader input = new BufferedReader(new FileReader(file))) {
|
||||
String line;
|
||||
while ((line = input.readLine()) != null)
|
||||
errorStringBuilder.append(line).append("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
file.delete();
|
||||
}
|
||||
|
||||
errorStringBuilder.append("\r\n\r\n");
|
||||
}
|
||||
|
||||
context.startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND).setType("message/rfc822")
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
.putExtra(Intent.EXTRA_EMAIL, new String[]{email})
|
||||
.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(application, BuildConfig.APPLICATION_ID + ".provider", crashLogsZip))
|
||||
.putExtra(Intent.EXTRA_SUBJECT, "InstaGrabber Crash Report")
|
||||
.putExtra(Intent.EXTRA_TEXT, errorStringBuilder.toString()), "Select an email app to send crash logs"));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
101
app/src/main/java/awaisomereport/ErrorReporterActivity.java
Executable file
101
app/src/main/java/awaisomereport/ErrorReporterActivity.java
Executable file
|
|
@ -0,0 +1,101 @@
|
|||
package awaisomereport;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import awais.instagrabber.R;
|
||||
|
||||
public final class ErrorReporterActivity extends Activity implements View.OnClickListener {
|
||||
private View btnReport;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_crash_error);
|
||||
|
||||
setFinishOnTouchOutside(false);
|
||||
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
final SpannableString crashTitle = new SpannableString(" " + getString(R.string.crash_title));
|
||||
crashTitle.setSpan(new CenteredImageSpan(this, android.R.drawable.stat_notify_error),
|
||||
0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
setTitle(crashTitle);
|
||||
|
||||
btnReport = findViewById(R.id.btnReport);
|
||||
btnReport.setOnClickListener(this);
|
||||
findViewById(R.id.btnCancel).setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(@NonNull final View v) {
|
||||
if (v == btnReport)
|
||||
CrashReporter.get(getApplication()).startCrashEmailIntent(this, false);
|
||||
finish();
|
||||
System.exit(10);
|
||||
}
|
||||
|
||||
public static class CenteredImageSpan extends ImageSpan {
|
||||
private WeakReference<Drawable> drawable;
|
||||
|
||||
public CenteredImageSpan(final Context context, final int drawableRes) {
|
||||
super(context, drawableRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize(@NonNull final Paint paint, final CharSequence text, final int start, final int end, @Nullable final Paint.FontMetricsInt fm) {
|
||||
final Drawable drawable = getCachedDrawable();
|
||||
final Rect rect = drawable.getBounds();
|
||||
|
||||
if (fm != null) {
|
||||
final Paint.FontMetricsInt pfm = paint.getFontMetricsInt();
|
||||
fm.ascent = pfm.ascent;
|
||||
fm.descent = pfm.descent;
|
||||
fm.top = pfm.top;
|
||||
fm.bottom = pfm.bottom;
|
||||
}
|
||||
|
||||
return rect.right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(@NonNull final Canvas canvas, final CharSequence text, final int start, final int end, final float x, final int top,
|
||||
final int y, final int bottom, @NonNull final Paint paint) {
|
||||
final Drawable drawable = getCachedDrawable();
|
||||
canvas.save();
|
||||
|
||||
final int drawableHeight = drawable.getIntrinsicHeight();
|
||||
final Paint.FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
|
||||
int transY = bottom - drawable.getBounds().bottom + (drawableHeight - fontMetricsInt.descent + fontMetricsInt.ascent) / 2;
|
||||
|
||||
canvas.translate(x, transY);
|
||||
drawable.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
private Drawable getCachedDrawable() {
|
||||
Drawable d = null;
|
||||
if (drawable != null) d = drawable.get();
|
||||
if (d == null) {
|
||||
d = getDrawable();
|
||||
drawable = new WeakReference<>(d);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
138
app/src/main/java/awaisomereport/LogCollector.java
Executable file
138
app/src/main/java/awaisomereport/LogCollector.java
Executable file
|
|
@ -0,0 +1,138 @@
|
|||
package awaisomereport;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import awais.instagrabber.BuildConfig;
|
||||
|
||||
public final class LogCollector {
|
||||
private final File logDir;
|
||||
|
||||
public LogCollector(@NonNull final Application app) {
|
||||
logDir = new File(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? app.getDataDir() : app.getFilesDir(),
|
||||
"ur_mom_gay_logs");
|
||||
|
||||
if (logDir.exists()) deleteRecursive(logDir);
|
||||
|
||||
if (logDir.mkdirs()) {
|
||||
// create log files to zip later
|
||||
for (final LogFile logFile : LogFile.values()) {
|
||||
try {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
new File(logDir, logFile.fileName).createNewFile();
|
||||
} catch (final IOException e) {
|
||||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public File getLogDir() {
|
||||
return logDir;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public final void appendException(@NonNull final Exception exception, @NonNull final LogFile logFile, @NonNull final String method,
|
||||
@Nullable final Pair<String, Object>... vars) {
|
||||
final File excepionFile = new File(logDir, logFile.fileName);
|
||||
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.append('\n').append('\n').append("----------------- ").append(method).append(" ------------------")
|
||||
.append('\n');
|
||||
|
||||
if (vars != null && vars.length > 0) {
|
||||
stringBuilder.append("Variables: ").append('\n');
|
||||
for (Pair<String, Object> var : vars)
|
||||
stringBuilder.append('\t').append(var.first).append(" : ")
|
||||
.append('\u201C').append(var.second).append('\u201D')
|
||||
.append(" (type: ").append(var.second == null ? "null" : var.second.getClass().getSimpleName()).append(')')
|
||||
.append('\n');
|
||||
stringBuilder.append("----------------------------------").append('\n');
|
||||
}
|
||||
|
||||
final Writer stringWriter = new StringWriter();
|
||||
try (final PrintWriter printWriter = new PrintWriter(stringWriter)) {
|
||||
exception.printStackTrace(printWriter);
|
||||
stringBuilder.append(stringWriter.toString());
|
||||
|
||||
// for AsyncTask crashes
|
||||
Throwable cause = exception.getCause();
|
||||
while (cause != null) {
|
||||
cause.printStackTrace(printWriter);
|
||||
stringBuilder.append(stringWriter.toString());
|
||||
cause = cause.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
try (final BufferedReader br = new BufferedReader(new FileReader(excepionFile))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) stringBuilder.append(line).append('\n');
|
||||
} catch (final Exception e) {
|
||||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
||||
}
|
||||
|
||||
stringBuilder.append('\n');
|
||||
|
||||
try (final BufferedWriter bw = new BufferedWriter(new FileWriter(excepionFile))) {
|
||||
bw.write(stringBuilder.toString());
|
||||
} catch (final Exception e) {
|
||||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
||||
}
|
||||
}
|
||||
|
||||
public enum LogFile {
|
||||
UTILS("utils.txt"),
|
||||
MAIN_HELPER("main-helper.txt"),
|
||||
////////////////////////
|
||||
ACTIVITY_STORY_VIEWER("act-story-viewer.txt"),
|
||||
////////////////////////
|
||||
ASYNC_DOWNLOADER("async-download.txt"),
|
||||
ASYNC_MAIN_POSTS_FETCHER("async-main-posts-fetcher.txt"),
|
||||
ASYNC_POST_FETCHER("async-single-post-fetcher.txt"),
|
||||
ASYNC_FEED_FETCHER("async-feed-fetcher.txt"),
|
||||
ASYNC_PROFILE_FETCHER("async-profile-fetcher.txt"),
|
||||
ASYNC_PROFILE_PICTURE_FETCHER("async-pfp-fetcher.txt"),
|
||||
ASYNC_STORY_STATUS_FETCHER("async-story-status-fetcher.txt"),
|
||||
ASYNC_DISCOVER_FETCHER("async-discover-fetcher.txt"),
|
||||
ASYNC_COMMENTS_FETCHER("async-comments-fetcher.txt"),
|
||||
ASYNC_FOLLOW_FETCHER("async-follow-fetcher.txt"),
|
||||
ASYNC_FEED_STORY_FETCHER("async-feed-story-fetcher.txt"),
|
||||
////////////////////////
|
||||
ASYNC_DMS("async-dms-inbox-fetcher.txt"),
|
||||
ASYNC_DMS_THREAD("async-dms-thread-fetcher.txt"),
|
||||
////////////////////////
|
||||
DATA_BOX_FAVORITES("data-box-favs.txt"),
|
||||
UTILS_EXPORT("utils-export.txt"),
|
||||
UTILS_IMPORT("utils-import.txt"),
|
||||
;
|
||||
private final String fileName;
|
||||
|
||||
LogFile(final String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteRecursive(@NonNull final File fileOrDirectory) {
|
||||
final File[] files;
|
||||
if (fileOrDirectory.isDirectory() && (files = fileOrDirectory.listFiles()) != null)
|
||||
for (final File child : files) deleteRecursive(child);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
fileOrDirectory.delete();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue