Add an email logs menu item that sends app data

This commit is contained in:
Aaron Culliney 2019-11-30 07:59:14 -08:00
parent 68e6fb768f
commit 2ef5abba2c
7 changed files with 197 additions and 165 deletions

View File

@ -326,7 +326,7 @@ public class Apple2Activity extends AppCompatActivity implements Apple2DiskChoos
logMessage(LogType.DEBUG, TAG, "Letting native save preferences...");
}
logMessage(LogType.DEBUG, TAG, "onPause()");
logMessage(LogType.INFO, TAG, "onPause() ...");
if (mView != null) {
mView.onPause();
}
@ -609,6 +609,7 @@ public class Apple2Activity extends AppCompatActivity implements Apple2DiskChoos
}
public void quitEmulator() {
logMessage(LogType.INFO, TAG, "Quitting...");
nativeOnQuit();
finish();
new Runnable() {

View File

@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class Apple2CrashHandler {
public final static String ALL_CRASH_FILE = "apple2ix_crash.zip";
public final static String ALL_CRASH_FILE = "apple2ix_data.zip";
public final static String javaCrashFileName = "jcrash.txt";
@ -211,6 +211,7 @@ public class Apple2CrashHandler {
Apple2Preferences.load(activity);
if (!(boolean) Apple2Preferences.getJSONPref(Apple2SettingsMenu.SETTINGS.CRASH)) {
_cleanCrashData(activity);
return;
}
@ -218,33 +219,9 @@ public class Apple2CrashHandler {
boolean previouslySentReport = mAlreadySentReport.get();
if (previouslySentReport) {
mAlreadySentReport.set(false);
// here we assume that the crash data was previously sent via email ... if not then we lost it =P
Apple2Activity.logMessage(Apple2Activity.LogType.DEBUG, TAG, "Cleaning up crash data ...");
int idx = 0;
File[] nativeCrashes = _nativeCrashFiles(activity);
for (File crash : nativeCrashes) {
if (!crash.delete()) {
Apple2Activity.logMessage(Apple2Activity.LogType.DEBUG, TAG, "Could not unlink crash : " + crash);
}
File processed = new File(_dumpPath2ProcessedPath(crash.getAbsolutePath()));
if (!processed.delete()) {
Apple2Activity.logMessage(Apple2Activity.LogType.DEBUG, TAG, "Could not unlink processed : " + processed);
}
}
File javaCrashFile = _javaCrashFile(activity);
if (!javaCrashFile.delete()) {
Apple2Activity.logMessage(Apple2Activity.LogType.DEBUG, TAG, "Could not unlink java crash : " + javaCrashFile);
}
// remove previous crash files
File allCrashFile = _getCrashFile(activity, ALL_CRASH_FILE);
Apple2Utils.writeFile(new StringBuilder(), allCrashFile);
allCrashFile.delete();
_cleanCrashData(activity);
return;
}
@ -257,7 +234,13 @@ public class Apple2CrashHandler {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
emailCrashesAndLogs(activity);
}
}).create();
activity.registerAndShowDialog(crashDialog);
}
public static void emailCrashesAndLogs(final Apple2Activity activity) {
final Apple2SplashScreen splashScreen = activity.getSplashScreen();
if (splashScreen != null) {
splashScreen.setDismissable(false);
@ -266,7 +249,7 @@ public class Apple2CrashHandler {
try {
bar.setVisibility(View.VISIBLE);
} catch (NullPointerException npe) {
/* could happen on early lifecycle crashes */
/* email logs doesn't show the splash screen */
}
new Thread(new Runnable() {
@ -356,12 +339,12 @@ public class Apple2CrashHandler {
}
});
}
summary.append("" + nativeCrashes.length + " native crashes\n");
summary.append("" + nativeCrashes.length + " Native dumps\n");
}
File javaCrashFile = _javaCrashFile(activity);
if (javaCrashFile.exists()) {
summary.append("Java Crash File\n");
summary.append("Java crash log\n");
allCrashFiles.add(javaCrashFile);
}
@ -387,7 +370,7 @@ public class Apple2CrashHandler {
bar.setVisibility(View.INVISIBLE);
splashScreen.setDismissable(true);
} catch (NullPointerException npe) {
/* could happen on early lifecycle crashes */
/* email logs doesn't show the splash screen */
}
}
});
@ -407,9 +390,6 @@ public class Apple2CrashHandler {
}
}).start();
}
}).create();
activity.registerAndShowDialog(crashDialog);
}
public void performCrash(int crashType) {
if (BuildConfig.DEBUG) {
@ -465,11 +445,11 @@ public class Apple2CrashHandler {
} while (attempts < maxAttempts);
}
private File _javaCrashFile(Apple2Activity activity) {
private static File _javaCrashFile(Apple2Activity activity) {
return new File(homeDir, javaCrashFileName);
}
private File[] _nativeLogs(Apple2Activity activity) {
private static File[] _nativeLogs(Apple2Activity activity) {
FilenameFilter logFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
File file = new File(dir, name);
@ -484,7 +464,7 @@ public class Apple2CrashHandler {
return new File(homeDir).listFiles(logFilter);
}
private File[] _nativeCrashFiles(Apple2Activity activity) {
private static File[] _nativeCrashFiles(Apple2Activity activity) {
FilenameFilter dmpFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
File file = new File(dir, name);
@ -509,11 +489,11 @@ public class Apple2CrashHandler {
return new File(homeDir).listFiles(dmpFilter);
}
private String _dumpPath2ProcessedPath(String crashPath) {
private static String _dumpPath2ProcessedPath(String crashPath) {
return crashPath.substring(0, crashPath.length() - 4) + ".txt";
}
private File _getCrashFile(Apple2Activity activity, String fileName) {
private static File _getCrashFile(Apple2Activity activity, String fileName) {
File file;
String storageState = Environment.getExternalStorageState();
if (storageState.equals(Environment.MEDIA_MOUNTED)) {
@ -524,7 +504,7 @@ public class Apple2CrashHandler {
return file;
}
private void _sendEmailToDeveloperWithCrashData(Apple2Activity activity, StringBuilder summary, File nativeCrashesZip) {
private static void _sendEmailToDeveloperWithCrashData(Apple2Activity activity, StringBuilder summary, File nativeCrashesZip) {
mAlreadySentReport.set(true);
// <sigh> ... the disaster that is early Android ... there does not appear to be a reliable way to start an
@ -533,13 +513,13 @@ public class Apple2CrashHandler {
// much text data in the EXTRA_TEXT ... </sigh>
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "apple2ix_crash@deadcode.org"/*non-zero variant is correct endpoint at the moment*/, null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Crasher");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "A2IX Report");
final int maxCharsEmail = 4096;
int len = summary.length();
len = len < maxCharsEmail ? len : maxCharsEmail;
String summaryData = summary.substring(0, len);
emailIntent.putExtra(Intent.EXTRA_TEXT, "The app crashed, please help!\n\n" + summaryData);
emailIntent.putExtra(Intent.EXTRA_TEXT, "A2IX app logs and crash data\n\n" + summaryData);
if (!nativeCrashesZip.setReadable(true, /*ownerOnly:*/false)) {
Apple2Activity.logMessage(Apple2Activity.LogType.DEBUG, TAG, "Oops, could not set crash file data readable!");
@ -552,14 +532,41 @@ public class Apple2CrashHandler {
Apple2Activity.logMessage(Apple2Activity.LogType.DEBUG, TAG, "AFTER START ACTIVITY ...");
}
private static void _cleanCrashData(Apple2Activity activity) {
Apple2Activity.logMessage(Apple2Activity.LogType.DEBUG, TAG, "Cleaning up crash data ...");
int idx = 0;
File[] nativeCrashes = _nativeCrashFiles(activity);
for (File crash : nativeCrashes) {
if (!crash.delete()) {
Apple2Activity.logMessage(Apple2Activity.LogType.DEBUG, TAG, "Could not unlink crash : " + crash);
}
File processed = new File(_dumpPath2ProcessedPath(crash.getAbsolutePath()));
if (!processed.delete()) {
Apple2Activity.logMessage(Apple2Activity.LogType.DEBUG, TAG, "Could not unlink processed : " + processed);
}
}
File javaCrashFile = _javaCrashFile(activity);
if (!javaCrashFile.delete()) {
Apple2Activity.logMessage(Apple2Activity.LogType.DEBUG, TAG, "Could not unlink java crash : " + javaCrashFile);
}
// remove previous crash files
File allCrashFile = _getCrashFile(activity, ALL_CRASH_FILE);
Apple2Utils.writeFile(new StringBuilder(), allCrashFile);
allCrashFile.delete();
}
private final static String TAG = "Apple2CrashHandler";
private final static Apple2CrashHandler sCrashHandler = new Apple2CrashHandler();
private String homeDir;
private static String homeDir;
private Thread.UncaughtExceptionHandler mDefaultExceptionHandler;
private AtomicBoolean mAlreadyRanCrashCheck = new AtomicBoolean(false);
private AtomicBoolean mAlreadySentReport = new AtomicBoolean(false);
private static AtomicBoolean mAlreadySentReport = new AtomicBoolean(false);
private static native void nativePerformCrash(int crashType); // testing

View File

@ -360,6 +360,22 @@ public class Apple2SettingsMenu extends Apple2AbstractMenu {
activity.registerAndShowDialog(dialog);
}
},
EMAIL_LOGS {
@Override
public final String getTitle(Apple2Activity activity) {
return activity.getResources().getString(R.string.preferences_email_logs);
}
@Override
public final String getSummary(Apple2Activity activity) {
return activity.getResources().getString(R.string.preferences_email_logs_summary);
}
@Override
public void handleSelection(final Apple2Activity activity, final Apple2AbstractMenu settingsMenu, boolean isChecked) {
Apple2CrashHandler.emailCrashesAndLogs(activity);
}
},
CRASH {
@Override
public final String getTitle(Apple2Activity activity) {

View File

@ -215,5 +215,7 @@
<string name="joystick_button_swipe_right_button_summary">Button to fire on swipe right</string>
<string name="key_del">[DEL]</string>
<string name="key_tab">[TAB]</string>
<string name="preferences_email_logs">Email logs</string>
<string name="preferences_email_logs_summary">Email logs to developer…</string>
</resources>

View File

@ -215,5 +215,7 @@
<string name="joystick_button_swipe_right_button_summary">Button to fire on swipe right</string>
<string name="key_del">[DEL]</string>
<string name="key_tab">[TAB]</string>
<string name="preferences_email_logs">Email logs</string>
<string name="preferences_email_logs_summary">Email logs to developer…</string>
</resources>

View File

@ -215,5 +215,7 @@
<string name="joystick_button_swipe_right_button_summary">Button to fire on swipe right</string>
<string name="key_del">[DEL]</string>
<string name="key_tab">[TAB]</string>
<string name="preferences_email_logs">Email logs</string>
<string name="preferences_email_logs_summary">Email logs to developer…</string>
</resources>

View File

@ -215,5 +215,7 @@
<string name="joystick_button_swipe_left_button_summary">Button to fire on swipe left</string>
<string name="key_del">[DEL]</string>
<string name="key_tab">[TAB]</string>
<string name="preferences_email_logs">Email logs</string>
<string name="preferences_email_logs_summary">Email logs to developer…</string>
</resources>