sentry: upload crashes after reading emu.cfg to comply with user choice

android: get rid of Send Logs button
This commit is contained in:
Flyinghead 2022-12-23 10:06:24 +01:00
parent 599bc8a823
commit 95a00a165a
8 changed files with 26 additions and 259 deletions

View File

@ -312,8 +312,6 @@ int main(int argc, char* argv[])
//appletSetFocusHandlingMode(AppletFocusHandlingMode_NoSuspend);
#endif
#if defined(USE_BREAKPAD)
auto async = std::async(std::launch::async, uploadCrashes, "/tmp");
google_breakpad::MinidumpDescriptor descriptor("/tmp");
google_breakpad::ExceptionHandler eh(descriptor, nullptr, dumpCallback, nullptr, true, -1);
#endif
@ -345,6 +343,10 @@ int main(int argc, char* argv[])
if (flycast_init(argc, argv))
die("Flycast initialization failed\n");
#if defined(USE_BREAKPAD)
auto async = std::async(std::launch::async, uploadCrashes, "/tmp");
#endif
mainui_loop();
#if defined(SUPPORT_X11)

View File

@ -2279,13 +2279,6 @@ static void gui_display_settings()
ImGui::Text("Driver Name: %s", GraphicsContext::Instance()->getDriverName().c_str());
ImGui::Text("Version: %s", GraphicsContext::Instance()->getDriverVersion().c_str());
#ifdef __ANDROID__
ImGui::Separator();
if (ImGui::Button("Send Logs")) {
void android_send_logs();
android_send_logs();
}
#endif
ImGui::PopStyleVar();
ImGui::EndTabItem();
}

View File

@ -873,12 +873,6 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
wchar_t tempDir[MAX_PATH + 1];
GetTempPathW(MAX_PATH + 1, tempDir);
nowide::stackstring nws;
static std::string tempDir8;
if (nws.convert(tempDir))
tempDir8 = nws.c_str();
auto async = std::async(std::launch::async, uploadCrashes, tempDir8);
static google_breakpad::CustomInfoEntry custom_entries[] = {
google_breakpad::CustomInfoEntry(L"prod", L"Flycast"),
google_breakpad::CustomInfoEntry(L"ver", L"" GIT_VERSION),
@ -909,6 +903,14 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
if (flycast_init(argc, argv) != 0)
die("Flycast initialization failed");
#ifdef USE_BREAKPAD
nowide::stackstring nws;
static std::string tempDir8;
if (nws.convert(tempDir))
tempDir8 = nws.c_str();
auto async = std::async(std::launch::async, uploadCrashes, tempDir8);
#endif
#ifdef TARGET_UWP
if (config::ContentPath.get().empty())
config::ContentPath.get().push_back(get_writable_config_path(""));

View File

@ -27,7 +27,6 @@ import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import com.reicast.emulator.config.Config;
import com.reicast.emulator.debug.GenerateLogs;
import com.reicast.emulator.emu.AudioBackend;
import com.reicast.emulator.emu.HttpClient;
import com.reicast.emulator.emu.JNIdc;
@ -407,27 +406,5 @@ public abstract class BaseGLActivity extends Activity implements ActivityCompat.
}
}
// Called from native code
protected void generateErrorLog() {
try {
new GenerateLogs(this).execute(getFilesDir().getAbsolutePath());
} catch (RuntimeException e) {
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setMessage("An error occurred retrieving the log file:\n\n"
+ e.getMessage());
dlgAlert.setTitle("Flycast Error");
dlgAlert.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
dlgAlert.setIcon(android.R.drawable.ic_dialog_info);
dlgAlert.setCancelable(false);
dlgAlert.create().show();
}
}
private static native void register(BaseGLActivity activity);
}

View File

@ -1,207 +0,0 @@
package com.reicast.emulator.debug;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import com.reicast.emulator.config.Config;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
public class GenerateLogs extends AsyncTask<String, Integer, String> {
private WeakReference<Context> mContext;
private static final String build_device = android.os.Build.DEVICE;
private static final String build_board = android.os.Build.BOARD;
private static final int build_sdk = android.os.Build.VERSION.SDK_INT;
private static final String DN = "Donut";
private static final String EC = "Eclair";
private static final String FR = "Froyo";
private static final String GB = "Gingerbread";
private static final String HC = "Honeycomb";
private static final String IC = "Ice Cream Sandwich";
private static final String JB = "JellyBean";
private static final String KK = "KitKat";
private static final String LL = "Lollipop";
private static final String MM = "Marshmallow";
private static final String NT = "Nougat";
private static final String NL = "New / No Label";
private static final String NF = "Not Found";
private String currentTime;
private String unHandledIOE;
public GenerateLogs(Context reference) {
this.mContext = new WeakReference<>(reference);
this.currentTime = String.valueOf(System.currentTimeMillis());
}
/**
* Obtain the specific parameters of the current device
*
*/
private String discoverCPUData() {
String s = "MODEL: " + Build.MODEL;
s += "\r\n";
s += "DEVICE: " + build_device;
s += "\r\n";
s += "BOARD: " + build_board;
s += "\r\n";
if (!String.valueOf(build_sdk).equals("")) {
String build_version = NF;
if (String.valueOf(build_sdk).equals("L")) {
build_version = "LP";
} else if (build_sdk >= 4 && build_sdk < 7) {
build_version = DN;
} else if (build_sdk == 7) {
build_version = EC;
} else if (build_sdk == 8) {
build_version = FR;
} else if (build_sdk >= 9 && build_sdk < 11) {
build_version = GB;
} else if (build_sdk >= 11 && build_sdk < 14) {
build_version = HC;
} else if (build_sdk >= 14 && build_sdk < 16) {
build_version = IC;
} else if (build_sdk >= 16 && build_sdk < 19) {
build_version = JB;
} else if (build_sdk >= 19 && build_sdk < 21) {
build_version = KK;
} else if (build_sdk >= 21 && build_sdk < 23) {
build_version = LL;
} else if (build_sdk >= 23 && build_sdk < 24) {
build_version = MM;
} else if (build_sdk >= 24 && build_sdk < 26) {
build_version = NT;
} else if (build_sdk >= 26 && build_sdk < 28) {
build_version = "Oreo";
} else if (build_sdk == 28) {
build_version = "Pie";
} else if (build_sdk > 28) {
build_version = NL;
}
s += build_version + " (" + build_sdk + ")";
} else {
String prop_build_version = "ro.build.version.release";
String prop_sdk_version = "ro.build.version.sdk";
String build_version = readOutput("/system/bin/getprop "
+ prop_build_version);
String sdk_version = readOutput("/system/bin/getprop "
+ prop_sdk_version);
s += build_version + " (" + sdk_version + ")";
}
return s;
}
/**
* Read the output of a shell command
*
* @param command
* The shell command being issued to the terminal
*/
public static String readOutput(String command) {
try {
Process p = Runtime.getRuntime().exec(command);
InputStream is = null;
if (p.waitFor() == 0) {
is = p.getInputStream();
} else {
is = p.getErrorStream();
}
BufferedReader br = new BufferedReader(new InputStreamReader(is),
2048);
String line = br.readLine();
br.close();
return line;
} catch (Exception ex) {
return "ERROR: " + ex.getMessage();
}
}
public void setUnhandled(String unHandledIOE) {
this.unHandledIOE = unHandledIOE;
}
@Override
protected String doInBackground(String... params) {
File logFile = new File(params[0], currentTime + ".txt");
Process mLogcatProc = null;
BufferedReader reader = null;
final StringBuilder log = new StringBuilder();
String separator = System.getProperty("line.separator");
log.append(discoverCPUData());
if (unHandledIOE != null) {
log.append(separator);
log.append(separator);
log.append("Unhandled Exceptions");
log.append(separator);
log.append(separator);
log.append(unHandledIOE);
}
try {
String line;
mLogcatProc = Runtime.getRuntime().exec(
new String[] { "logcat", "-ds", "reicast:V" });
reader = new BufferedReader(new InputStreamReader(
mLogcatProc.getInputStream()));
log.append(separator);
log.append(separator);
log.append("Native Interface Output");
log.append(separator);
log.append(separator);
while ((line = reader.readLine()) != null) {
log.append(line);
log.append(separator);
}
reader.close();
File memory = new File(mContext.get().getFilesDir(), "mem_alloc.txt");
if (memory.exists()) {
log.append(separator);
log.append(separator);
log.append("Memory Allocation Table");
log.append(separator);
log.append(separator);
FileInputStream fis = new FileInputStream(memory);
reader = new BufferedReader(new InputStreamReader(fis));
while ((line = reader.readLine()) != null) {
log.append(line);
log.append(separator);
}
fis.close();
reader.close();
}
BufferedWriter writer = new BufferedWriter(new FileWriter(logFile));
writer.write(log.toString());
writer.flush();
writer.close();
return log.toString();
} catch (IOException e) {
// Could not generate log file
// Writing a log is redundant
}
return null;
}
@Override
protected void onPostExecute(final String response) {
if (response != null) {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mContext.get()
.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("logcat", response);
clipboard.setPrimaryClip(clip);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Config.git_issues));
mContext.get().startActivity(browserIntent);
}
}
}

View File

@ -189,10 +189,6 @@ extern "C" JNIEXPORT jstring JNICALL Java_com_reicast_emulator_emu_JNIdc_initEnv
std::string path(jchar);
env->ReleaseStringUTFChars(directory, jchar);
static std::string crashPath;
static cThread uploadThread(uploadCrashThread, &crashPath);
crashPath = path;
uploadThread.Start();
google_breakpad::MinidumpDescriptor descriptor(path);
exceptionHandler = new google_breakpad::ExceptionHandler(descriptor, nullptr, dumpCallback, nullptr, true, -1);
@ -243,6 +239,16 @@ extern "C" JNIEXPORT jstring JNICALL Java_com_reicast_emulator_emu_JNIdc_initEnv
int rc = flycast_init(0, NULL);
if (rc == -1)
msg = env->NewStringUTF("Memory initialization failed");
#ifdef USE_BREAKPAD
else
{
static std::string crashPath;
static cThread uploadThread(uploadCrashThread, &crashPath);
crashPath = get_writable_config_path("");
uploadThread.Start();
}
#endif
return msg;
}
else
@ -662,13 +668,6 @@ void vjoy_stop_editing(bool canceled)
jvm_attacher.getEnv()->CallVoidMethod(g_activity, VJoyStopEditingMID, canceled);
}
void android_send_logs()
{
JNIEnv *env = jvm_attacher.getEnv();
jmethodID generateErrorLogMID = env->GetMethodID(env->GetObjectClass(g_activity), "generateErrorLog", "()V");
env->CallVoidMethod(g_activity, generateErrorLogMID);
}
extern "C" JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setButtons(JNIEnv *env, jobject obj, jbyteArray data)
{
u32 len = env->GetArrayLength(data);

View File

@ -8,7 +8,6 @@
#include "SDLMain.h"
#include <sys/param.h> /* for MAXPATHLEN */
#include <unistd.h>
#include <future>
#include "rend/gui.h"
#include "oslib/oslib.h"
@ -310,8 +309,6 @@ static bool dumpCallback(const char *dump_dir, const char *minidump_id, void *co
- (void) applicationDidFinishLaunching: (NSNotification *) note
{
#ifdef USE_BREAKPAD
auto async = std::async(std::launch::async, uploadCrashes, "/tmp");
google_breakpad::ExceptionHandler eh("/tmp", NULL, dumpCallback, NULL, true, NULL);
task_set_exception_ports(mach_task_self(), EXC_MASK_BAD_ACCESS, MACH_PORT_NULL, EXCEPTION_DEFAULT, 0);
#endif

View File

@ -21,6 +21,7 @@
#include "oslib/oslib.h"
#include "emulator.h"
#include "rend/mainui.h"
#include <future>
int darw_printf(const char* text, ...)
{
@ -135,6 +136,9 @@ extern "C" int SDL_main(int argc, char *argv[])
CFRelease(mainBundle);
emu_flycast_init();
#ifdef USE_BREAKPAD
auto async = std::async(std::launch::async, uploadCrashes, "/tmp");
#endif
mainui_loop();