Added debug helper

This commit is contained in:
M66B 2023-12-15 12:36:20 +01:00
parent 2b00772111
commit 673947f60c
6 changed files with 2012 additions and 1903 deletions

View File

@ -0,0 +1,38 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2023 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.os.Bundle;
import org.json.JSONException;
import java.io.IOException;
public class DebugHelper {
static final String CRASH_LOG_NAME = "crash.log";
static EntityMessage getDebugInfo(Context context, String source, int title, Throwable ex, String log, Bundle args) throws IOException, JSONException {
return null;
}
static void writeCrashLog(Context context, Throwable ex) {
}
}

File diff suppressed because it is too large Load Diff

View File

@ -499,11 +499,15 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
@Override
protected Long onExecute(Context context, Bundle args) throws IOException, JSONException {
return Log.getDebugInfo(context, "setup", R.string.title_debug_info_remark, null, null, args).id;
EntityMessage m = DebugHelper.getDebugInfo(context,
"setup", R.string.title_debug_info_remark, null, null, args);
return (m == null ? null : m.id);
}
@Override
protected void onExecuted(Bundle args, Long id) {
if (id == null)
return;
startActivity(new Intent(ActivitySetup.this, ActivityCompose.class)
.putExtra("action", "edit")
.putExtra("id", id));

View File

@ -1502,7 +1502,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
new SimpleTask<Long>() {
@Override
protected Long onExecute(Context context, Bundle args) throws Throwable {
File file = new File(context.getFilesDir(), Log.CRASH_LOG_NAME);
File file = new File(context.getFilesDir(), DebugHelper.CRASH_LOG_NAME);
if (file.exists()) {
StringBuilder sb = new StringBuilder();
try {
@ -1512,7 +1512,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
sb.append(line).append("\r\n");
}
return Log.getDebugInfo(context, "crash", R.string.title_crash_info_remark, null, sb.toString(), null).id;
EntityMessage m = DebugHelper.getDebugInfo(context,
"crash", R.string.title_crash_info_remark, null, sb.toString(), null);
return (m == null ? null : m.id);
} finally {
Helper.secureDelete(file);
}
@ -1523,11 +1525,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override
protected void onExecuted(Bundle args, Long id) {
if (id != null)
startActivity(
new Intent(ActivityView.this, ActivityCompose.class)
.putExtra("action", "edit")
.putExtra("id", id));
if (id == null)
return;
startActivity(
new Intent(ActivityView.this, ActivityCompose.class)
.putExtra("action", "edit")
.putExtra("id", id));
}
@Override
@ -1535,7 +1538,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
ToastEx.makeText(ActivityView.this,
Log.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
}
}.execute(this, new Bundle(), Log.CRASH_LOG_NAME);
}.execute(this, new Bundle(), DebugHelper.CRASH_LOG_NAME);
}
private void checkUpdate(boolean always) {
@ -2277,14 +2280,17 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
protected Long onExecute(Context context, Bundle args) throws IOException, JSONException {
boolean send = args.getBoolean("send");
long id = Log.getDebugInfo(context, "main", R.string.title_debug_info_remark, null, null, args).id;
EntityMessage m = DebugHelper.getDebugInfo(context,
"main", R.string.title_debug_info_remark, null, null, args);
if (m == null)
return null;
if (send) {
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage draft = db.message().getMessage(id);
EntityMessage draft = db.message().getMessage(m.id);
if (draft != null) {
draft.folder = EntityFolder.getOutbox(context).id;
db.message().updateMessage(draft);
@ -2301,11 +2307,14 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
}
}
return id;
return m.id;
}
@Override
protected void onExecuted(Bundle args, Long id) {
if (id == null)
return;
boolean sent = args.getBoolean("sent");
if (sent) {
ToastEx.makeText(ActivityView.this, R.string.title_debug_info_send, Toast.LENGTH_LONG).show();

View File

@ -151,7 +151,7 @@ public class ApplicationEx extends Application
if (BuildConfig.BETA_RELEASE ||
!Helper.isPlayStoreInstall())
Log.writeCrashLog(ApplicationEx.this, ex);
DebugHelper.writeCrashLog(ApplicationEx.this, ex);
if (prev != null)
prev.uncaughtException(thread, ex);

File diff suppressed because it is too large Load Diff