From bc35c3341f2095ec0001ae2bbe27ca1a54cf9d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 6 Jul 2023 19:21:19 +0200 Subject: [PATCH] Allow putting a user string in reported java exceptions --- UI/DevScreens.cpp | 8 +++---- android/jni/app-android.cpp | 2 +- .../src/org/ppsspp/ppsspp/NativeActivity.java | 22 +++++++++---------- android/src/org/ppsspp/ppsspp/NativeApp.java | 6 ++++- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 5a72701da8..2c056115a4 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -801,19 +801,19 @@ void SystemInfoScreen::CreateTabs() { internals->Add(new ItemHeader(si->T("Notification tests"))); internals->Add(new Choice(si->T("Error")))->OnClick.Add([&](UI::EventParams &) { - g_OSD.Show(OSDType::MESSAGE_ERROR, si->T("Error")); + g_OSD.Show(OSDType::MESSAGE_ERROR, "Error"); return UI::EVENT_DONE; }); internals->Add(new Choice(si->T("Warning")))->OnClick.Add([&](UI::EventParams &) { - g_OSD.Show(OSDType::MESSAGE_WARNING, si->T("Warning"), "Some\nAdditional\nDetail"); + g_OSD.Show(OSDType::MESSAGE_WARNING, "Warning", "Some\nAdditional\nDetail"); return UI::EVENT_DONE; }); internals->Add(new Choice(si->T("Info")))->OnClick.Add([&](UI::EventParams &) { - g_OSD.Show(OSDType::MESSAGE_INFO, si->T("Info")); + g_OSD.Show(OSDType::MESSAGE_INFO, "Info"); return UI::EVENT_DONE; }); internals->Add(new Choice(si->T("Success")))->OnClick.Add([&](UI::EventParams &) { - g_OSD.Show(OSDType::MESSAGE_SUCCESS, si->T("Success")); + g_OSD.Show(OSDType::MESSAGE_SUCCESS, "Success"); return UI::EVENT_DONE; }); internals->Add(new ItemHeader(si->T("Progress tests"))); diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index f68c277ffd..a448422874 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -1038,7 +1038,7 @@ void System_Notify(SystemNotification notification) { PushCommand("sustainedPerfMode", ""); break; case SystemNotification::TEST_JAVA_EXCEPTION: - PushCommand("testException", ""); + PushCommand("testException", "This is a test exception"); break; default: break; diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index e9d8aaf7ed..ebacfdcdc2 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -428,7 +428,7 @@ public abstract class NativeActivity extends Activity { additionalStorageDirs = s.toString(); } catch (Exception e) { - NativeApp.reportException(e); + NativeApp.reportException(e, null); Log.e(TAG, "Failed to get SD storage dirs: " + e.toString()); } @@ -1161,7 +1161,7 @@ public abstract class NativeActivity extends Activity { NativeApp.sendRequestResult(imageRequestId, false, "", 0); } } catch (Exception e) { - NativeApp.reportException(e); + NativeApp.reportException(e, null); Log.w(TAG, "Exception receiving image: " + e); } imageRequestId = -1; @@ -1180,7 +1180,7 @@ public abstract class NativeActivity extends Activity { } catch (Exception e) { Log.w(TAG, "Exception getting permissions for document: " + e.toString()); NativeApp.sendRequestResult(fileRequestId, false, "", 0); - NativeApp.reportException(e); + NativeApp.reportException(e, selectedFile.toString()); fileRequestId = -1; return; } @@ -1205,7 +1205,7 @@ public abstract class NativeActivity extends Activity { getContentResolver().takePersistableUriPermission(selectedDirectoryUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } } catch (Exception e) { - NativeApp.reportException(e); + NativeApp.reportException(e, selectedDirectoryUri.toString()); Log.w(TAG, "Exception getting permissions for document: " + e.toString()); // Intentionally don't return - see below. } @@ -1349,7 +1349,7 @@ public abstract class NativeActivity extends Activity { startActivity(i); return true; } catch (Exception e) { - NativeApp.reportException(e); + NativeApp.reportException(e, params); // No browser? Log.e(TAG, e.toString()); return false; @@ -1366,7 +1366,7 @@ public abstract class NativeActivity extends Activity { startActivity(Intent.createChooser(send, "E-mail the app author!")); return true; } catch (Exception e) { // For example, android.content.ActivityNotFoundException - NativeApp.reportException(e); + NativeApp.reportException(e, params); Log.e(TAG, e.toString()); return false; } @@ -1378,7 +1378,7 @@ public abstract class NativeActivity extends Activity { startActivityForResult(i, RESULT_LOAD_IMAGE); return true; } catch (Exception e) { // For example, android.content.ActivityNotFoundException - NativeApp.reportException(e); + NativeApp.reportException(e, params); imageRequestId = -1; Log.e(TAG, e.toString()); return false; @@ -1396,7 +1396,7 @@ public abstract class NativeActivity extends Activity { startActivityForResult(intent, RESULT_OPEN_DOCUMENT); // intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri); } catch (Exception e) { - NativeApp.reportException(e); + NativeApp.reportException(e, params); fileRequestId = -1; Log.e(TAG, e.toString()); return false; @@ -1412,7 +1412,7 @@ public abstract class NativeActivity extends Activity { startActivityForResult(intent, RESULT_OPEN_DOCUMENT_TREE); return true; } catch (Exception e) { - NativeApp.reportException(e); + NativeApp.reportException(e, params); folderRequestId = -1; Log.e(TAG, e.toString()); return false; @@ -1427,7 +1427,7 @@ public abstract class NativeActivity extends Activity { startActivity(shareIntent); return true; } catch (Exception e) { // For example, android.content.ActivityNotFoundException - NativeApp.reportException(e); + NativeApp.reportException(e, params); Log.e(TAG, e.toString()); return false; } @@ -1579,7 +1579,7 @@ public abstract class NativeActivity extends Activity { try { throw new Exception(); } catch (Exception e) { - NativeApp.reportException(e); + NativeApp.reportException(e, params); } } return false; diff --git a/android/src/org/ppsspp/ppsspp/NativeApp.java b/android/src/org/ppsspp/ppsspp/NativeApp.java index 8dcdcd4106..937c10cf34 100644 --- a/android/src/org/ppsspp/ppsspp/NativeApp.java +++ b/android/src/org/ppsspp/ppsspp/NativeApp.java @@ -60,8 +60,12 @@ public class NativeApp { public static native void pushCameraImageAndroid(byte[] image); // Wrappers - public static void reportException(Exception e) { + public static void reportException(Exception e, String data) { String str = e.toString() + "\n" + e.getMessage() + "\n"; + if (data != null) { + str += data + "\n"; + } + // could also use import android.util.Log; String stackTrace = Log.getStackTraceString(exception); int count = 0; for (StackTraceElement ste : e.getStackTrace()) { str += ste + "\n";