From 41a302de43dc7770639159b39d89c4250e1fb8c9 Mon Sep 17 00:00:00 2001 From: ToadKing Date: Fri, 22 Feb 2013 14:57:34 -0500 Subject: [PATCH] (Android) show message on ROM load failure/crash --- .../src/org/retroarch/browser/RetroArch.java | 33 +++++++++++++++++-- frontend/frontend_android.c | 23 +++++++++++++ frontend/frontend_android.h | 1 + 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/android/phoenix/src/org/retroarch/browser/RetroArch.java b/android/phoenix/src/org/retroarch/browser/RetroArch.java index 8c103fb2a3..7b51272711 100644 --- a/android/phoenix/src/org/retroarch/browser/RetroArch.java +++ b/android/phoenix/src/org/retroarch/browser/RetroArch.java @@ -59,11 +59,13 @@ public class RetroArch extends Activity implements AdapterView.OnItemClickListener { private IconAdapter adapter; static private final int ACTIVITY_LOAD_ROM = 0; + static private final int ACTIVITY_NATIVE_ACTIVITY = 1; static private String libretro_path; static private Double report_refreshrate; static private final String TAG = "RetroArch-Phoenix"; private ConfigFile config; private ConfigFile core_config; + private String return_file; private final double getDisplayRefreshRate() { // Android is *very* likely to screw this up. @@ -282,6 +284,12 @@ public class RetroArch extends Activity implements } } + if (getCacheDir() != null && getCacheDir().getAbsolutePath() != null) { + return_file = getCacheDir().getAbsolutePath() + File.pathSeparator + ".return"; + } else { + return_file = getDefaultConfigPath() + ".ret"; + } + this.setVolumeControlStream(AudioManager.STREAM_MUSIC); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { @@ -352,7 +360,7 @@ public class RetroArch extends Activity implements else if (getCacheDir() != null && getCacheDir().getAbsolutePath() != null) return getCacheDir().getAbsolutePath() + File.separator + "retroarch.cfg"; else // emergency fallback, all else failed - return "/mnt/sd/retroarch.cfg"; + return "/mnt/sdcard/retroarch.cfg"; } private void updateConfigFile() { @@ -456,6 +464,7 @@ public class RetroArch extends Activity implements switch (requestCode) { case ACTIVITY_LOAD_ROM: if (data.getStringExtra("PATH") != null) { + new File(return_file).delete(); Toast.makeText(this, "Loading: [" + data.getStringExtra("PATH") + "]...", Toast.LENGTH_SHORT).show(); @@ -463,10 +472,30 @@ public class RetroArch extends Activity implements myIntent.putExtra("ROM", data.getStringExtra("PATH")); myIntent.putExtra("LIBRETRO", libretro_path); myIntent.putExtra("CONFIGFILE", getDefaultConfigPath()); + myIntent.putExtra("RETURN", return_file); myIntent.putExtra("IME", current_ime); - startActivity(myIntent); + startActivityForResult(myIntent, ACTIVITY_NATIVE_ACTIVITY); } break; + case ACTIVITY_NATIVE_ACTIVITY: + Log.i(TAG, "native return"); + AlertDialog.Builder builder = new AlertDialog.Builder(this).setNeutralButton("OK", null); + try { + DataInputStream cacheStream = new DataInputStream(new FileInputStream(return_file)); + int value = cacheStream.readInt(); + cacheStream.close(); + Log.i(TAG, "native return value"); + Log.i(TAG, "native return value:" + value); + if (value != 0) { + builder.setTitle("Error").setMessage("RetroArch Could not load the chosen ROM").show(); + } + } catch (FileNotFoundException e) { + builder.setTitle("Crash").setMessage("RetroArch Crashed").show(); + } catch (IOException e) { + builder.setTitle("Error").setMessage("RetroArch Could not load the chosen ROM").show(); + } + new File(return_file).delete(); + break; } } diff --git a/frontend/frontend_android.c b/frontend/frontend_android.c index cee92d11dc..cf3ae7b336 100644 --- a/frontend/frontend_android.c +++ b/frontend/frontend_android.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "frontend_android.h" #include "../android/native/jni/jni_macros.h" @@ -280,6 +281,12 @@ static bool android_app_start_main(struct android_app *android_app, int *init_re strlcpy(out_args.in, "IME", sizeof(out_args.in)); jni_get(&in_params, &out_args); + // Return value file + out_args.out = android_app->return_file; + out_args.out_sizeof = sizeof(android_app->return_file); + strlcpy(out_args.in, "RETURN", sizeof(out_args.in)); + jni_get(&in_params, &out_args); + (*in_params.java_vm)->DetachCurrentThread(in_params.java_vm); RARCH_LOG("Checking arguments passed ...\n"); @@ -287,6 +294,9 @@ static bool android_app_start_main(struct android_app *android_app, int *init_re RARCH_LOG("Libretro path: [%s].\n", libretro_path); RARCH_LOG("Config file: [%s].\n", config_file); RARCH_LOG("Current IME: [%s].\n", android_app->current_ime); + RARCH_LOG("Return file: [%s].\n", android_app->return_file); + + unlink(android_app->return_file); struct rarch_main_wrap args = {0}; @@ -371,6 +381,19 @@ exit: #endif rarch_main_clear_state(); + int bs_return = bswap_32(init_ret); + FILE *return_file = fopen(android_app->return_file, "w"); + if (return_file) + { + fwrite(&bs_return, 4, 1, return_file); + fclose(return_file); + } + + // returning from the native activity too fast can make the Java frontend not reappear + // work around it only if we fail to load the ROM + if (init_ret != 0) + usleep(1000000); + RARCH_LOG("android_app_destroy!"); if (android_app->inputQueue != NULL) AInputQueue_detachLooper(android_app->inputQueue); diff --git a/frontend/frontend_android.h b/frontend/frontend_android.h index 16e6f21f9f..591493705a 100644 --- a/frontend/frontend_android.h +++ b/frontend/frontend_android.h @@ -49,6 +49,7 @@ struct android_app AInputQueue* pendingInputQueue; ANativeWindow* pendingWindow; char current_ime[PATH_MAX]; + char return_file[PATH_MAX]; }; enum {