From 188d7cbe4fc50d9dda90faa604bbeb09cd759a92 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Wed, 12 Feb 2014 19:34:19 -0500 Subject: [PATCH 1/8] Handle the popup navigation through buttons for the lazy --- .../com/reicast/emulator/emu/GL2JNIActivity.java | 12 ++++++++++-- .../com/reicast/emulator/emu/OnScreenMenu.java | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/shell/android/src/com/reicast/emulator/emu/GL2JNIActivity.java b/shell/android/src/com/reicast/emulator/emu/GL2JNIActivity.java index 17cce0aa4..ea2a3e965 100644 --- a/shell/android/src/com/reicast/emulator/emu/GL2JNIActivity.java +++ b/shell/android/src/com/reicast/emulator/emu/GL2JNIActivity.java @@ -2,6 +2,7 @@ package com.reicast.emulator.emu; import java.util.Arrays; import java.util.HashMap; +import java.util.Vector; import tv.ouya.console.api.OuyaController; import android.annotation.TargetApi; @@ -43,6 +44,8 @@ public class GL2JNIActivity extends Activity { public static HashMap deviceId_deviceDescriptor = new HashMap(); public static HashMap deviceDescriptor_PlayerNum = new HashMap(); + + private Vector popups = new Vector(); int map[][]; @@ -55,7 +58,7 @@ public class GL2JNIActivity extends Activity { prefs = PreferenceManager.getDefaultSharedPreferences(this); ConfigureFragment.getCurrentConfiguration(prefs); - menu = new OnScreenMenu(GL2JNIActivity.this, prefs); + menu = new OnScreenMenu(GL2JNIActivity.this, prefs, popups); popUp = menu.createPopup(); /* * try { //int rID = @@ -563,7 +566,12 @@ public class GL2JNIActivity extends Activity { if (!popUp.isShowing()) { displayPopUp(popUp); } else { - popUp.dismiss(); + for (PopupWindow popup : popups) { + if (popup.isShowing()) { + popup.dismiss(); + popups.remove(popup); + } + } } return true; } diff --git a/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java b/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java index d14dd6cd2..d9b2920a9 100644 --- a/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java +++ b/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java @@ -1,6 +1,7 @@ package com.reicast.emulator.emu; import java.io.File; +import java.util.Vector; import android.app.Activity; import android.content.Context; @@ -29,10 +30,12 @@ public class OnScreenMenu { private boolean limitframes; private boolean audiodisabled; + private Vector popups; + private File sdcard = Environment.getExternalStorageDirectory(); private String home_directory = sdcard + "/dc"; - public OnScreenMenu(Context mContext, SharedPreferences prefs) { + public OnScreenMenu(Context mContext, SharedPreferences prefs, Vector popups) { if (mContext instanceof GL2JNIActivity) { this.mContext = (GL2JNIActivity) mContext; } @@ -56,6 +59,7 @@ public class OnScreenMenu { hlay.addView(addbut(R.drawable.up, new OnClickListener() { public void onClick(View v) { + popups.remove(popUp); popUp.dismiss(); } }), params); @@ -70,6 +74,7 @@ public class OnScreenMenu { hlay.addView(addbut(R.drawable.config, new OnClickListener() { public void onClick(View v) { displayConfigPopup(popUp); + popups.remove(popUp); popUp.dismiss(); } }), params); @@ -77,6 +82,7 @@ public class OnScreenMenu { hlay.addView(addbut(R.drawable.disk_unknown, new OnClickListener() { public void onClick(View v) { displayDebugPopup(popUp); + popups.remove(popUp); popUp.dismiss(); } }), params); @@ -91,6 +97,7 @@ public class OnScreenMenu { // layout.addView(hlay,params); popUp.setContentView(hlay); + popups.add(popUp); return popUp; } @@ -106,6 +113,7 @@ public class OnScreenMenu { hlay.addView(addbut(R.drawable.up, new OnClickListener() { public void onClick(View v) { + popups.remove(popUpDebug); popUpDebug.dismiss(); mContext.displayPopUp(popUp); } @@ -141,11 +149,13 @@ public class OnScreenMenu { hlay.addView(addbut(R.drawable.close, new OnClickListener() { public void onClick(View v) { + popups.remove(popUpDebug); popUpDebug.dismiss(); } }), debugParams); popUpDebug.setContentView(hlay); + popups.add(popUpDebug); mContext.displayDebug(popUpDebug); } @@ -161,6 +171,7 @@ public class OnScreenMenu { hlay.addView(addbut(R.drawable.up, new OnClickListener() { public void onClick(View v) { + popups.remove(popUpConfig); popUpConfig.dismiss(); mContext.displayPopUp(popUp); } @@ -261,11 +272,13 @@ public class OnScreenMenu { hlay.addView(addbut(R.drawable.close, new OnClickListener() { public void onClick(View v) { + popups.remove(popUpConfig); popUpConfig.dismiss(); } }), configParams); popUpConfig.setContentView(hlay); + popups.add(popUpConfig); mContext.displayConfig(popUpConfig); } From 5485f2f16e2d4efcb1d2287cf18bb3e6ce1888b9 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Wed, 12 Feb 2014 19:42:44 -0500 Subject: [PATCH 2/8] Handle irrational decision to run screaming from file listing --- .../com/reicast/emulator/MainActivity.java | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/shell/android/src/com/reicast/emulator/MainActivity.java b/shell/android/src/com/reicast/emulator/MainActivity.java index ccce25311..7a35d4b06 100644 --- a/shell/android/src/com/reicast/emulator/MainActivity.java +++ b/shell/android/src/com/reicast/emulator/MainActivity.java @@ -416,20 +416,19 @@ public class MainActivity extends SlidingFragmentActivity implements Fragment fragment = (FileBrowser) getSupportFragmentManager() .findFragmentByTag("MAIN_BROWSER"); if (fragment != null && fragment.isVisible()) { - MainActivity.this.finish(); + boolean readyToQuit = true; + if (fragment.getArguments() != null) { + readyToQuit = fragment.getArguments().getBoolean( + "ImgBrowse", true); + } + if (readyToQuit) { + MainActivity.this.finish(); + } else { + launchMainFragment(fragment); + } return true; } else { - fragment = new FileBrowser(); - Bundle args = new Bundle(); - args.putBoolean("ImgBrowse", true); - args.putString("browse_entry", null); - args.putBoolean("games_entry", false); - fragment.setArguments(args); - getSupportFragmentManager() - .beginTransaction() - .replace(R.id.fragment_container, fragment, - "MAIN_BROWSER").commit(); - setTitle(getString(R.string.browser)); + launchMainFragment(fragment); return true; } @@ -437,6 +436,20 @@ public class MainActivity extends SlidingFragmentActivity implements return super.onKeyDown(keyCode, event); } + + private void launchMainFragment(Fragment fragment) { + fragment = new FileBrowser(); + Bundle args = new Bundle(); + args.putBoolean("ImgBrowse", true); + args.putString("browse_entry", null); + args.putBoolean("games_entry", false); + fragment.setArguments(args); + getSupportFragmentManager() + .beginTransaction() + .replace(R.id.fragment_container, fragment, + "MAIN_BROWSER").commit(); + setTitle(getString(R.string.browser)); + } @Override protected void onPause() { From 89ab2420c9333c2064af3c7117a68ccb1c7dd5f2 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Wed, 12 Feb 2014 20:07:58 -0500 Subject: [PATCH 3/8] Fix an issue with popup definition coming after vector calls --- .../src/com/reicast/emulator/emu/GL2JNIActivity.java | 11 ++--------- .../src/com/reicast/emulator/emu/OnScreenMenu.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/shell/android/src/com/reicast/emulator/emu/GL2JNIActivity.java b/shell/android/src/com/reicast/emulator/emu/GL2JNIActivity.java index ea2a3e965..6be05eeea 100644 --- a/shell/android/src/com/reicast/emulator/emu/GL2JNIActivity.java +++ b/shell/android/src/com/reicast/emulator/emu/GL2JNIActivity.java @@ -44,8 +44,6 @@ public class GL2JNIActivity extends Activity { public static HashMap deviceId_deviceDescriptor = new HashMap(); public static HashMap deviceDescriptor_PlayerNum = new HashMap(); - - private Vector popups = new Vector(); int map[][]; @@ -58,7 +56,7 @@ public class GL2JNIActivity extends Activity { prefs = PreferenceManager.getDefaultSharedPreferences(this); ConfigureFragment.getCurrentConfiguration(prefs); - menu = new OnScreenMenu(GL2JNIActivity.this, prefs, popups); + menu = new OnScreenMenu(GL2JNIActivity.this, prefs); popUp = menu.createPopup(); /* * try { //int rID = @@ -566,12 +564,7 @@ public class GL2JNIActivity extends Activity { if (!popUp.isShowing()) { displayPopUp(popUp); } else { - for (PopupWindow popup : popups) { - if (popup.isShowing()) { - popup.dismiss(); - popups.remove(popup); - } - } + menu.dismissPopUps(); } return true; } diff --git a/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java b/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java index d9b2920a9..4dc2ca71a 100644 --- a/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java +++ b/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java @@ -35,10 +35,11 @@ public class OnScreenMenu { private File sdcard = Environment.getExternalStorageDirectory(); private String home_directory = sdcard + "/dc"; - public OnScreenMenu(Context mContext, SharedPreferences prefs, Vector popups) { + public OnScreenMenu(Context mContext, SharedPreferences prefs) { if (mContext instanceof GL2JNIActivity) { this.mContext = (GL2JNIActivity) mContext; } + popups = new Vector(); if (prefs != null) { this.prefs = prefs; home_directory = prefs.getString("home_directory", home_directory); @@ -308,4 +309,13 @@ public class OnScreenMenu { return but; } + + public void dismissPopUps() { + for (PopupWindow popup : popups) { + if (popup.isShowing()) { + popup.dismiss(); + popups.remove(popup); + } + } + } } From d9233b3440c2af98af2b7a46d7957909ec28c1ff Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Wed, 12 Feb 2014 22:12:43 -0500 Subject: [PATCH 4/8] Account for devices with small screens and stock DPI sets --- shell/android/res/values/dimens.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/android/res/values/dimens.xml b/shell/android/res/values/dimens.xml index 9aee7513d..1f787f33d 100644 --- a/shell/android/res/values/dimens.xml +++ b/shell/android/res/values/dimens.xml @@ -4,7 +4,7 @@ 8dp 16dp - 160dp + 80dp 10dp 15dp From 4d322feacc77e67e0e6d88750341e93cfefc57b7 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Thu, 13 Feb 2014 00:40:54 -0500 Subject: [PATCH 5/8] In case of a memory allocation failure, print current readout --- core/hw/mem/_vmem.cpp | 4 +-- core/linux/common.cpp | 31 +++++++++++++++++++ .../com/reicast/emulator/MainActivity.java | 2 ++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/core/hw/mem/_vmem.cpp b/core/hw/mem/_vmem.cpp index b6f4a89f5..3c7677cf2 100644 --- a/core/hw/mem/_vmem.cpp +++ b/core/hw/mem/_vmem.cpp @@ -561,8 +561,8 @@ error: fd = ashmem_create_region(0,RAM_SIZE + VRAM_SIZE +ARAM_SIZE); if (false)//this causes writebacks to flash -> slow and stuttery { - fd = open("/data/data/com.example.droidcast/dcnzorz_mem",O_CREAT|O_RDWR|O_TRUNC,S_IRWXU|S_IRWXG|S_IRWXO); - unlink("/data/data/com.example.droidcast/dcnzorz_mem"); + fd = open("/data/data/com.reicast.emulator/files/dcnzorz_mem",O_CREAT|O_RDWR|O_TRUNC,S_IRWXU|S_IRWXG|S_IRWXO); + unlink("/data/data/com.reicast.emulator/files/dcnzorz_mem"); } #endif diff --git a/core/linux/common.cpp b/core/linux/common.cpp index 8c3ebabbf..6f6427727 100644 --- a/core/linux/common.cpp +++ b/core/linux/common.cpp @@ -155,12 +155,43 @@ void VArray2::LockRegion(u32 offset,u32 size) } } +void print_mem_addr() +{ + FILE *ifp, *ofp; + char *mode = "r"; + char outputFilename[] = "/data/data/com.reicast.emulator/files/reicast_mem.txt"; + + ifp = fopen("/proc/self/maps", mode); + + if (ifp == NULL) { + fprintf(stderr, "Can't open input file /proc/self/maps!\n"); + exit(1); + } + + ofp = fopen(outputFilename, "w"); + + if (ofp == NULL) { + fprintf(stderr, "Can't open output file %s!\n", + outputFilename); + exit(1); + } + + char line [ 512 ]; + while (fgets(line, sizeof line, ifp) != NULL) { + fprintf(ofp, "%s\n", line); + } + + fclose(ifp); + fclose(ofp); +} + void VArray2::UnLockRegion(u32 offset,u32 size) { u32 inpage=offset & PAGE_MASK; u32 rv=mprotect (data+offset-inpage, size+inpage, PROT_READ | PROT_WRITE); if (rv!=0) { + print_mem_addr(); printf("mprotect(%08X,%08X,RW) failed: %d | %d\n",data+offset-inpage,size+inpage,rv,errno); die("mprotect failed ..\n"); } diff --git a/shell/android/src/com/reicast/emulator/MainActivity.java b/shell/android/src/com/reicast/emulator/MainActivity.java index 7a35d4b06..61a7b7997 100644 --- a/shell/android/src/com/reicast/emulator/MainActivity.java +++ b/shell/android/src/com/reicast/emulator/MainActivity.java @@ -60,6 +60,8 @@ public class MainActivity extends SlidingFragmentActivity implements home_directory = mPrefs.getString("home_directory", home_directory); JNIdc.config(home_directory); + getFilesDir().mkdir(); + mUEHandler = new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable error) { if (error != null) { From 9281d2f2adbf19436fa961199e7f9e1fcb766a5d Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Thu, 13 Feb 2014 00:51:58 -0500 Subject: [PATCH 6/8] Append the memory allocation table to error log submission --- core/linux/common.cpp | 2 +- .../reicast/emulator/debug/GenerateLogs.java | 59 ++++++++++--------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/core/linux/common.cpp b/core/linux/common.cpp index 6f6427727..ce81b23de 100644 --- a/core/linux/common.cpp +++ b/core/linux/common.cpp @@ -178,7 +178,7 @@ void print_mem_addr() char line [ 512 ]; while (fgets(line, sizeof line, ifp) != NULL) { - fprintf(ofp, "%s\n", line); + fprintf(ofp, "%s", line); } fclose(ifp); diff --git a/shell/android/src/com/reicast/emulator/debug/GenerateLogs.java b/shell/android/src/com/reicast/emulator/debug/GenerateLogs.java index 6733360fc..ea05a1a55 100644 --- a/shell/android/src/com/reicast/emulator/debug/GenerateLogs.java +++ b/shell/android/src/com/reicast/emulator/debug/GenerateLogs.java @@ -3,6 +3,7 @@ package com.reicast.emulator.debug; 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; @@ -14,7 +15,7 @@ import android.os.AsyncTask; import android.os.Build; public class GenerateLogs extends AsyncTask { - + public static final String build_model = android.os.Build.MODEL; public static final String build_device = android.os.Build.DEVICE; public static final String build_board = android.os.Build.BOARD; @@ -29,7 +30,7 @@ public class GenerateLogs extends AsyncTask { public static final String JB = "JellyBean"; public static final String KK = "KitKat"; public static final String NF = "Not Found"; - + private String unHandledIOE; private Context mContext; @@ -37,14 +38,14 @@ public class GenerateLogs extends AsyncTask { public GenerateLogs(Context mContext) { this.mContext = mContext; - this.currentTime = String.valueOf(System.currentTimeMillis()); + this.currentTime = String.valueOf(System.currentTimeMillis()); } @SuppressLint("NewApi") protected void onPreExecute() { - + } - + private String discoverCPUData() { String s = "MODEL: " + Build.MODEL; s += "\r\n"; @@ -102,7 +103,7 @@ public class GenerateLogs extends AsyncTask { return "ERROR: " + ex.getMessage(); } } - + public void setUnhandled(String unHandledIOE) { this.unHandledIOE = unHandledIOE; } @@ -190,21 +191,25 @@ public class GenerateLogs extends AsyncTask { reader.close(); mLogcatProc = null; reader = null; -// mLogcatProc = Runtime.getRuntime().exec( -// new String[] { "logcat", "-d", "newdc:V *:S" }); -// reader = new BufferedReader(new InputStreamReader( -// mLogcatProc.getInputStream())); -// log.append(separator); -// log.append(separator); -// log.append("Native Library Output"); -// log.append(separator); -// log.append(separator); -// while ((line = reader.readLine()) != null) { -// log.append(line); -// log.append(separator); -// } -// reader.close(); -// reader = null; + File memory = new File(mContext.getFilesDir(), "reicast_mem.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(); + fis = null; + reader.close(); + reader = null; + + } File file = new File(logOuput); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(log.toString()); @@ -221,12 +226,12 @@ public class GenerateLogs extends AsyncTask { protected void onPostExecute(String response) { if (response != null && !response.equals(null)) { UploadLogs mUploadLogs = new UploadLogs(mContext, currentTime); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - mUploadLogs.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, - response); - } else { - mUploadLogs.execute(response); - } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + mUploadLogs.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, + response); + } else { + mUploadLogs.execute(response); + } } } } From 60d3521d47a9884712ee682c30f1375cd9e8d1cd Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Thu, 13 Feb 2014 01:21:10 -0500 Subject: [PATCH 7/8] Rename the file to avoid confusion with proprietary app files --- core/linux/common.cpp | 2 +- shell/android/src/com/reicast/emulator/debug/GenerateLogs.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/linux/common.cpp b/core/linux/common.cpp index ce81b23de..d30909dab 100644 --- a/core/linux/common.cpp +++ b/core/linux/common.cpp @@ -159,7 +159,7 @@ void print_mem_addr() { FILE *ifp, *ofp; char *mode = "r"; - char outputFilename[] = "/data/data/com.reicast.emulator/files/reicast_mem.txt"; + char outputFilename[] = "/data/data/com.reicast.emulator/files/mem_alloc.txt"; ifp = fopen("/proc/self/maps", mode); diff --git a/shell/android/src/com/reicast/emulator/debug/GenerateLogs.java b/shell/android/src/com/reicast/emulator/debug/GenerateLogs.java index ea05a1a55..821b85a28 100644 --- a/shell/android/src/com/reicast/emulator/debug/GenerateLogs.java +++ b/shell/android/src/com/reicast/emulator/debug/GenerateLogs.java @@ -191,7 +191,7 @@ public class GenerateLogs extends AsyncTask { reader.close(); mLogcatProc = null; reader = null; - File memory = new File(mContext.getFilesDir(), "reicast_mem.txt"); + File memory = new File(mContext.getFilesDir(), "mem_alloc.txt"); if (memory.exists()) { log.append(separator); log.append(separator); @@ -208,7 +208,6 @@ public class GenerateLogs extends AsyncTask { fis = null; reader.close(); reader = null; - } File file = new File(logOuput); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); From c3a7260dc1d2faa0cf11540c97796d02e0fce58b Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Thu, 13 Feb 2014 02:41:29 -0500 Subject: [PATCH 8/8] Moving the dismissal call to prevent an inevitable merge fail --- .../com/reicast/emulator/emu/OnScreenMenu.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java b/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java index 4dc2ca71a..131e98af4 100644 --- a/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java +++ b/shell/android/src/com/reicast/emulator/emu/OnScreenMenu.java @@ -295,6 +295,15 @@ public class OnScreenMenu { frames_up.setEnabled(true); } } + + public void dismissPopUps() { + for (PopupWindow popup : popups) { + if (popup.isShowing()) { + popup.dismiss(); + popups.remove(popup); + } + } + } public static int getPixelsFromDp(float dps, Context context) { return (int) (dps * context.getResources().getDisplayMetrics().density + 0.5f); @@ -309,13 +318,4 @@ public class OnScreenMenu { return but; } - - public void dismissPopUps() { - for (PopupWindow popup : popups) { - if (popup.isShowing()) { - popup.dismiss(); - popups.remove(popup); - } - } - } }