diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-11-27 10:42:10 -0500 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-11-27 10:42:10 -0500 |
commit | a7293b4a66c374f9ed421cb29f288f1754612871 (patch) | |
tree | 70de3904660431b1fa6d47af548fcc3c6a231ddf | |
parent | f169a26488f29c51f30b763233d7bb8c8ca8eae6 (diff) | |
parent | 40a708fd0ef71342ccc7cd24553f5cfe57b126d4 (diff) | |
download | AntennaPod-a7293b4a66c374f9ed421cb29f288f1754612871.zip |
Merge pull request #1422 from mfietz/crash_report_mail
Log Crash Report
9 files changed, 95 insertions, 34 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/CrashReportWriter.java b/app/src/main/java/de/danoeh/antennapod/CrashReportWriter.java new file mode 100644 index 000000000..17942a93c --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/CrashReportWriter.java @@ -0,0 +1,49 @@ +package de.danoeh.antennapod; + +import android.os.Build; +import android.util.Log; + +import org.apache.commons.io.IOUtils; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +import de.danoeh.antennapod.core.preferences.UserPreferences; + +public class CrashReportWriter implements Thread.UncaughtExceptionHandler { + + private static final String TAG = "CrashReportWriter"; + + private final Thread.UncaughtExceptionHandler defaultHandler; + + public CrashReportWriter() { + defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); + } + + public static File getFile() { + return new File(UserPreferences.getDataFolder(null), "crash-report.log"); + } + + @Override + public void uncaughtException(Thread thread, Throwable ex) { + File path = getFile(); + PrintWriter out = null; + try { + out = new PrintWriter(new FileWriter(path)); + out.println("[ Environment ]"); + out.println("Android version: " + Build.VERSION.RELEASE); + out.println("AntennaPod version: " + BuildConfig.VERSION_NAME); + out.println("Phone model: " + Build.MODEL); + out.println(); + out.println("[ StackTrace ]"); + ex.printStackTrace(out); + } catch (IOException e) { + Log.e(TAG, Log.getStackTraceString(e)); + } finally { + IOUtils.closeQuietly(out); + } + defaultHandler.uncaughtException(thread, ex); + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java index 83bc9afb2..835f43f40 100644 --- a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java +++ b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod; import android.app.Application; -import android.content.res.Configuration; import android.os.Build; import android.os.StrictMode; @@ -27,10 +26,6 @@ public class PodcastApp extends Application { } } - private static final String TAG = "PodcastApp"; - - private static float LOGICAL_DENSITY; - private static PodcastApp singleton; public static PodcastApp getInstance() { @@ -41,6 +36,8 @@ public class PodcastApp extends Application { public void onCreate() { super.onCreate(); + Thread.setDefaultUncaughtExceptionHandler(new CrashReportWriter()); + if(BuildConfig.DEBUG) { StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() @@ -57,7 +54,6 @@ public class PodcastApp extends Application { } singleton = this; - LOGICAL_DENSITY = getResources().getDisplayMetrics().density; PodDBAdapter.init(this); UpdateManager.init(this); @@ -68,15 +64,6 @@ public class PodcastApp extends Application { Iconify.with(new FontAwesomeModule()); SPAUtil.sendSPAppsQueryFeedsIntent(this); - } - - public static float getLogicalDensity() { - return LOGICAL_DENSITY; - } - - public boolean isLargeScreen() { - return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE - || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE; + } - } } diff --git a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlExportWorker.java b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlExportWorker.java index 3940eb8b6..5c24c2822 100644 --- a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlExportWorker.java +++ b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlExportWorker.java @@ -49,7 +49,7 @@ public class OpmlExportWorker extends AsyncTask<Void, Void, Void> { OpmlWriter opmlWriter = new OpmlWriter(); if (output == null) { output = new File( - UserPreferences.getDataFolder(context, EXPORT_DIR), + UserPreferences.getDataFolder(EXPORT_DIR), DEFAULT_OUTPUT_NAME); if (output.exists()) { Log.w(TAG, "Overwriting previously exported file."); diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index 73d7da0f2..94f5d822e 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -8,6 +8,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; +import android.net.Uri; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.Build; @@ -34,6 +35,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import de.danoeh.antennapod.CrashReportWriter; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.AboutActivity; import de.danoeh.antennapod.activity.DirectoryChooserActivity; @@ -169,7 +171,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - if(Build.VERSION.SDK_INT >= 19) { + if (Build.VERSION.SDK_INT >= 19) { showChooseDataFolderDialog(); } else { Intent intent = new Intent(activity, DirectoryChooserActivity.class); @@ -254,7 +256,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc setParallelDownloadsText(value); return true; } - } catch(NumberFormatException e) { + } catch (NumberFormatException e) { return false; } } @@ -263,17 +265,19 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } ); // validate and set correct value: number of downloads between 1 and 50 (inclusive) - final EditText ev = ((EditTextPreference)ui.findPreference(UserPreferences.PREF_PARALLEL_DOWNLOADS)).getEditText(); + final EditText ev = ((EditTextPreference) ui.findPreference(UserPreferences.PREF_PARALLEL_DOWNLOADS)).getEditText(); ev.addTextChangedListener(new TextWatcher() { @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} + public void onTextChanged(CharSequence s, int start, int before, int count) { + } @Override public void afterTextChanged(Editable s) { - if(s.length() > 0) { + if (s.length() > 0) { try { int value = Integer.valueOf(s.toString()); if (value <= 0) { @@ -281,7 +285,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } else if (value > 50) { ev.setText("50"); } - } catch(NumberFormatException e) { + } catch (NumberFormatException e) { ev.setText("6"); } ev.setSelection(ev.getText().length()); @@ -386,11 +390,23 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } } ); + ui.findPreference("prefSendCrashReport").setOnPreferenceClickListener(preference -> { + Intent emailIntent = new Intent(Intent.ACTION_SEND); + emailIntent.setType("text/plain"); + String to[] = { "Martin.Fietz@gmail.com" }; + emailIntent .putExtra(Intent.EXTRA_EMAIL, to); + // the attachment + emailIntent .putExtra(Intent.EXTRA_STREAM, Uri.fromFile(CrashReportWriter.getFile())); + // the mail subject + emailIntent .putExtra(Intent.EXTRA_SUBJECT, "AntennaPod Crash Report"); + String intentTitle = ui.getActivity().getString(R.string.send_email); + ui.getActivity().startActivity(Intent.createChooser(emailIntent, intentTitle)); + return true; + }); buildEpisodeCleanupPreference(); buildSmartMarkAsPlayedPreference(); buildAutodownloadSelectedNetworsPreference(); - setSelectedNetworksEnabled(UserPreferences - .isEnableAutodownloadWifiFilter()); + setSelectedNetworksEnabled(UserPreferences.isEnableAutodownloadWifiFilter()); } public void onResume() { @@ -527,6 +543,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY) .setEnabled(UserPreferences.isEnableAutodownload()); + ui.findPreference("prefSendCrashReport").setEnabled(CrashReportWriter.getFile().exists()); + if (Build.VERSION.SDK_INT >= 16) { ui.findPreference(UserPreferences.PREF_SONIC).setEnabled(true); } else { @@ -558,7 +576,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } private void setDataFolderText() { - File f = UserPreferences.getDataFolder(ui.getActivity(), null); + File f = UserPreferences.getDataFolder(null); if (f != null) { ui.findPreference(PreferenceController.PREF_CHOOSE_DATA_DIR) .setSummary(f.getAbsolutePath()); @@ -677,7 +695,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc private void showChooseDataFolderDialog() { Context context = ui.getActivity(); - String dataFolder = UserPreferences.getDataFolder(context, null).getAbsolutePath(); + String dataFolder = UserPreferences.getDataFolder(null).getAbsolutePath(); int selectedIndex = -1; File[] mediaDirs = ContextCompat.getExternalFilesDirs(context, null); String[] folders = new String[mediaDirs.length]; diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 38350155a..a6256b7b8 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -245,6 +245,10 @@ <Preference android:key="prefAbout" android:title="@string/about_pref"/> + <Preference + android:key="prefSendCrashReport" + android:title="@string/crash_report_title" + android:summary="@string/crash_report_sum"/> </PreferenceCategory> <PreferenceCategory android:title="@string/experimental_pref"> diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index 6de546d3b..428d1d7d3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -520,7 +520,7 @@ public class UserPreferences { * @return The data folder that has been requested or null if the folder * could not be created. */ - public static File getDataFolder(Context context, String type) { + public static File getDataFolder(String type) { String strDir = prefs.getString(PREF_DATA_FOLDER, null); if (strDir == null) { Log.d(TAG, "Using default data folder"); @@ -542,7 +542,7 @@ public class UserPreferences { for (int i = 0; i < dirs.length; i++) { if (dirs.length > 0) { if (i < dirs.length - 1) { - dataDir = getDataFolder(context, dirs[i]); + dataDir = getDataFolder(dirs[i]); if (dataDir == null) { return null; } @@ -593,7 +593,7 @@ public class UserPreferences { * available */ private static void createImportDirectory() { - File importDir = getDataFolder(context, IMPORT_DIR); + File importDir = getDataFolder(IMPORT_DIR); if (importDir != null) { if (importDir.exists()) { Log.d(TAG, "Import directory already exists"); diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java index 318060abc..ee079c068 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java @@ -334,7 +334,7 @@ public class DownloadRequester { private File getExternalFilesDirOrThrowException(Context context, String type) throws DownloadRequestException { - File result = UserPreferences.getDataFolder(context, type); + File result = UserPreferences.getDataFolder(type); if (result == null) { throw new DownloadRequestException( "Failed to access external storage"); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java index dea380937..248f2bf32 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java @@ -19,7 +19,7 @@ public class StorageUtils { private static final String TAG = "StorageUtils"; public static boolean storageAvailable(Context context) { - File dir = UserPreferences.getDataFolder(context, null); + File dir = UserPreferences.getDataFolder(null); if (dir != null) { return dir.exists() && dir.canRead() && dir.canWrite(); } else { @@ -52,7 +52,7 @@ public class StorageUtils { */ public static long getFreeSpaceAvailable() { StatFs stat = new StatFs(UserPreferences.getDataFolder( - ClientConfig.applicationCallbacks.getApplicationInstance(), null).getAbsolutePath()); + null).getAbsolutePath()); long availableBlocks; long blockSize; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 151c0b915..575724427 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -364,6 +364,9 @@ <string name="pref_smart_mark_as_played_disabled">Disabled</string> <string name="pref_image_cache_size_title">Image Cache Size</string> <string name="pref_image_cache_size_sum">Size of the disk cache for images.</string> + <string name="crash_report_title">Crash Report</string> + <string name="crash_report_sum">Send the latest crash report via e-mail</string> + <string name="send_email">Send e-mail</string> <string name="experimental_pref">Experimental</string> <string name="pref_sonic_title">Sonic media player</string> <string name="pref_sonic_message">Use built-in sonic media player as a replacement for Prestissimo</string> |