| Index: src/org/adblockplus/android/CrashHandler.java |
| diff --git a/src/org/adblockplus/android/CrashHandler.java b/src/org/adblockplus/android/CrashHandler.java |
| index 25b54eff2a2c376a5421445533e7d0538f5b2c1d..025f6c13ec996cf3b75ce8a680caf0a26dc52848 100644 |
| --- a/src/org/adblockplus/android/CrashHandler.java |
| +++ b/src/org/adblockplus/android/CrashHandler.java |
| @@ -33,107 +33,112 @@ import android.util.Log; |
| */ |
| public class CrashHandler implements UncaughtExceptionHandler |
| { |
| - public static final String REPORT_FILE = "AdblockPlus_Crash_Report.txt"; |
| - private UncaughtExceptionHandler defaultUEH; |
| - private NotificationManager notificationManager; |
| - private Context context; |
| + public final static String REPORT_FILE = "AdblockPlus_Crash_Report.txt"; |
| + |
| + private final UncaughtExceptionHandler defaultUEH; |
| + private final Context context; |
| + private NotificationManager notificationManager; |
| private boolean generateReport; |
| private boolean restoreProxy; |
| private String host; |
| private String port; |
| private String excl; |
| - public CrashHandler(Context context) |
| + public CrashHandler(final Context context) |
| { |
| - defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); |
| + this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); |
| this.context = context; |
| - notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); |
| - generateReport = false; |
| - restoreProxy = false; |
| + this.notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); |
| + this.generateReport = false; |
| + this.restoreProxy = false; |
| } |
| public UncaughtExceptionHandler getDefault() |
| { |
| - return defaultUEH; |
| + return this.defaultUEH; |
| } |
| @Override |
| - public void uncaughtException(Thread t, Throwable e) |
| + public void uncaughtException(final Thread t, final Throwable e) |
| { |
| - if (generateReport) |
| - writeToFile(e, REPORT_FILE); |
| + if (this.generateReport) |
| + { |
| + this.writeToFile(e, REPORT_FILE); |
| + } |
| - if (restoreProxy) |
| - clearProxySettings(); |
| + if (this.restoreProxy) |
| + { |
| + this.clearProxySettings(); |
| + } |
| - if (notificationManager != null) |
| + if (this.notificationManager != null) |
| { |
| try |
| { |
| - notificationManager.cancel(ProxyService.ONGOING_NOTIFICATION_ID); |
| + this.notificationManager.cancel(ProxyService.ONGOING_NOTIFICATION_ID); |
| } |
| - catch (Throwable ex) |
| + catch (final Throwable ex) |
| { |
| ex.printStackTrace(); |
| } |
| } |
| - notificationManager = null; |
| + this.notificationManager = null; |
| - defaultUEH.uncaughtException(t, e); |
| + this.defaultUEH.uncaughtException(t, e); |
| } |
| - public void generateReport(boolean report) |
| + public void generateReport(final boolean report) |
| { |
| - generateReport = report; |
| + this.generateReport = report; |
| } |
| @SuppressLint("WorldReadableFiles") |
| - private void writeToFile(Throwable error, String filename) |
| + private void writeToFile(final Throwable error, final String filename) |
| { |
| Log.e("DCR", "Writing crash report"); |
| int versionCode = -1; |
| try |
| { |
| - PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); |
| + final PackageInfo pi = this.context.getPackageManager().getPackageInfo(this.context.getPackageName(), 0); |
| versionCode = pi.versionCode; |
| } |
| - catch (NameNotFoundException ex) |
| + catch (final NameNotFoundException ex) |
| { |
| } |
| try |
| { |
| - PrintWriter pw = new PrintWriter(context.openFileOutput(filename, Context.MODE_WORLD_READABLE)); |
| + final PrintWriter pw = new PrintWriter(this.context.openFileOutput(filename, Context.MODE_WORLD_READABLE)); |
| // Write Android version |
| pw.println(Build.VERSION.SDK_INT); |
| // Write application build number |
| pw.println(versionCode); |
| // Write exception data |
| - printThrowable(error, pw); |
| - Throwable cause = error.getCause(); |
| + this.printThrowable(error, pw); |
| + final Throwable cause = error.getCause(); |
| // Write cause data |
| if (cause != null) |
| { |
| pw.println("cause"); |
| - printThrowable(cause, pw); |
| + this.printThrowable(cause, pw); |
| } |
| pw.flush(); |
| pw.close(); |
| } |
| - catch (Throwable e) |
| + catch (final Throwable e) |
| { |
| e.printStackTrace(); |
| } |
| } |
| - private void printThrowable(Throwable error, PrintWriter pw) |
| + private void printThrowable(final Throwable error, final PrintWriter pw) |
| { |
| // Use simplest format for speed - we do not have much time |
| pw.println(error.getClass().getName()); |
| pw.println(error.getMessage()); |
| - StackTraceElement[] trace = error.getStackTrace(); |
| - for (StackTraceElement element : trace) |
| + final StackTraceElement[] trace = error.getStackTrace(); |
| + for (final StackTraceElement element : trace) |
| { |
| pw.print(element.getClassName()); |
| pw.print("|"); |
| @@ -148,28 +153,28 @@ public class CrashHandler implements UncaughtExceptionHandler |
| } |
| } |
| - public void saveProxySettings(String host, String port, String excl) |
| + public void saveProxySettings(final String host, final String port, final String excl) |
| { |
| Log.e("DCR", "Saving proxy " + host + ":" + port + "/" + excl); |
| this.host = host; |
| this.port = port; |
| this.excl = excl; |
| - restoreProxy = true; |
| + this.restoreProxy = true; |
| } |
| public void clearProxySettings() |
| { |
| Log.e("DCR", "Clearing proxy"); |
| - restoreProxy = false; |
| + this.restoreProxy = false; |
| int p = 0; |
| try |
| { |
| - p = Integer.valueOf(port); |
| + p = Integer.valueOf(this.port); |
| } |
| - catch (NumberFormatException e) |
| + catch (final NumberFormatException e) |
| { |
| // ignore - no valid port, it will be correctly processed later |
| } |
| - ProxySettings.setConnectionProxy(context, host, p, excl); |
| + ProxySettings.setConnectionProxy(this.context, this.host, p, this.excl); |
| } |
| } |