Merge pull request #1422 from mfietz/crash_report_mail
Log Crash Report
This commit is contained in:
commit
a7293b4a66
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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.");
|
||||
|
@ -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];
|
||||
|
@ -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">
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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) {
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user