Merge pull request #17672 from hrydgard/android-show-exceptions

Android: Show some Java exceptions as they happen
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2023-07-06 20:24:06 +02:00
commit 16efa1d877
5 files changed
+54 -5

No files matched your search

+1
View File
@@ -196,6 +196,7 @@ enum class SystemNotification {
SUSTAINED_PERF_CHANGE,
POLL_CONTROLLERS,
TOGGLE_DEBUG_CONSOLE, // TODO: Kinda weird, just ported forward.
TEST_JAVA_EXCEPTION,
};
std::string System_GetProperty(SystemProperty prop);
+10 -5
View File
@@ -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")));
@@ -833,7 +833,12 @@ void SystemInfoScreen::CreateTabs() {
g_OSD.RemoveProgressBar("testprogress", 0.25f);
return UI::EVENT_DONE;
});
#if PPSSPP_PLATFORM(ANDROID)
internals->Add(new Choice(si->T("Exception")))->OnClick.Add([&](UI::EventParams &) {
System_Notify(SystemNotification::TEST_JAVA_EXCEPTION);
return UI::EVENT_DONE;
});
#endif
}
void AddressPromptScreen::CreatePopupContents(UI::ViewGroup *parent) {
+5
View File
@@ -1037,6 +1037,9 @@ void System_Notify(SystemNotification notification) {
case SystemNotification::SUSTAINED_PERF_CHANGE:
PushCommand("sustainedPerfMode", "");
break;
case SystemNotification::TEST_JAVA_EXCEPTION:
PushCommand("testException", "This is a test exception");
break;
default:
break;
}
@@ -1285,6 +1288,8 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendMessageFromJava(JNI
} else if (msg == "core_powerSaving") {
// Forward.
System_PostUIMessage(msg.c_str(), prm.c_str());
} else if (msg == "exception") {
g_OSD.Show(OSDType::MESSAGE_ERROR, std::string("Java Exception"), prm, 10.0f);
} else {
ERROR_LOG(SYSTEM, "Got unexpected message from Java, ignoring: %s / %s", msg.c_str(), prm.c_str());
}
@@ -428,6 +428,7 @@ public abstract class NativeActivity extends Activity {
additionalStorageDirs = s.toString();
}
catch (Exception e) {
NativeApp.reportException(e, null);
Log.e(TAG, "Failed to get SD storage dirs: " + e.toString());
}
@@ -1156,6 +1157,7 @@ public abstract class NativeActivity extends Activity {
NativeApp.sendRequestResult(imageRequestId, false, "", 0);
}
} catch (Exception e) {
NativeApp.reportException(e, null);
Log.w(TAG, "Exception receiving image: " + e);
}
imageRequestId = -1;
@@ -1174,6 +1176,8 @@ 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, selectedFile.toString());
fileRequestId = -1;
return;
}
// Even if we got an exception getting permissions, try to pass along the file. Maybe this version of Android
@@ -1185,6 +1189,7 @@ public abstract class NativeActivity extends Activity {
} else if (requestCode == RESULT_OPEN_DOCUMENT_TREE) {
if (resultCode != RESULT_OK || data == null) {
NativeApp.sendRequestResult(folderRequestId, false, "", 0);
folderRequestId = -1;
return;
}
Uri selectedDirectoryUri = data.getData();
@@ -1196,7 +1201,9 @@ 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, selectedDirectoryUri.toString());
Log.w(TAG, "Exception getting permissions for document: " + e.toString());
// Intentionally don't return - see below.
}
// Even if we got an exception getting permissions, try to pass along the file. Maybe this version of Android
// doesn't need it. If we can't access it, we'll fail in some other way later.
@@ -1338,6 +1345,7 @@ public abstract class NativeActivity extends Activity {
startActivity(i);
return true;
} catch (Exception e) {
NativeApp.reportException(e, params);
// No browser?
Log.e(TAG, e.toString());
return false;
@@ -1354,6 +1362,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, params);
Log.e(TAG, e.toString());
return false;
}
@@ -1365,6 +1374,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, params);
imageRequestId = -1;
Log.e(TAG, e.toString());
return false;
@@ -1382,6 +1392,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, params);
fileRequestId = -1;
Log.e(TAG, e.toString());
return false;
@@ -1397,6 +1408,7 @@ public abstract class NativeActivity extends Activity {
startActivityForResult(intent, RESULT_OPEN_DOCUMENT_TREE);
return true;
} catch (Exception e) {
NativeApp.reportException(e, params);
folderRequestId = -1;
Log.e(TAG, e.toString());
return false;
@@ -1411,6 +1423,7 @@ public abstract class NativeActivity extends Activity {
startActivity(shareIntent);
return true;
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
NativeApp.reportException(e, params);
Log.e(TAG, e.toString());
return false;
}
@@ -1558,6 +1571,12 @@ public abstract class NativeActivity extends Activity {
// Only keep the screen bright ingame.
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
} else if (command.equals("testException")) {
try {
throw new Exception();
} catch (Exception e) {
NativeApp.reportException(e, params);
}
}
return false;
}
@@ -58,4 +58,23 @@ public class NativeApp {
public static native void setGpsDataAndroid(long time, float hdop, float latitude, float longitude, float altitude, float speed, float bearing);
public static native void setSatInfoAndroid(short index, short id, short elevation, short azimuth, short snr, short good);
public static native void pushCameraImageAndroid(byte[] image);
// Wrappers
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";
// Only bother with the top of the stack.
if (count > 3) {
break;
}
count++;
}
NativeApp.sendMessageFromJava("exception", str);
}
}