diff --git a/build.gradle b/build.gradle index dfb6c0fffb..bee1f1b45d 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,6 @@ android { } dependencies { - compile 'com.android.support:support-v4:23.2.0' - compile 'com.android.support:support-annotations:23.2.0' + compile 'com.android.support:support-v4:23.2.1' + compile 'com.android.support:support-annotations:23.2.1' } diff --git a/src/main/java/org/acra/dialog/BaseCrashReportDialog.java b/src/main/java/org/acra/dialog/BaseCrashReportDialog.java index fb0835ca4d..a46df520e8 100644 --- a/src/main/java/org/acra/dialog/BaseCrashReportDialog.java +++ b/src/main/java/org/acra/dialog/BaseCrashReportDialog.java @@ -2,9 +2,9 @@ import android.app.Activity; import android.os.Bundle; -import android.support.annotation.CallSuper; import android.support.annotation.Nullable; import android.widget.Toast; + import org.acra.ACRA; import org.acra.ACRAConstants; import org.acra.collector.CrashReportData; @@ -16,6 +16,7 @@ import java.io.File; import java.io.IOException; +import java.io.Serializable; import static org.acra.ACRA.LOG_TAG; import static org.acra.ReportField.USER_COMMENT; @@ -23,18 +24,17 @@ /** * Activity which implements the base functionality for a CrashReportDialog - * Activities which extend from this class can override onCreate() to create a custom view, - * but they must call super.onCreate() at the beginning of the method. + * Activities which extend from this class can override init to create a custom view. * - * The methods sendCrash(comment, usrEmail) and cancelReports() can be used to send or cancel + * The methods sendCrash(comment, userEmail) and cancelReports() can be used to send or cancel * sending of reports respectively. * * This Activity will be instantiated with 3 (or 4) arguments: *
    - *
  1. {@link ACRAConstants#EXTRA_REPORT_FILE_NAME}
  2. - *
  3. {@link ACRAConstants#EXTRA_REPORT_EXCEPTION}
  4. - *
  5. {@link ACRAConstants#EXTRA_REPORT_CONFIG}
  6. - *
  7. {@link ACRAConstants#EXTRA_FORCE_CANCEL} (optional)
  8. + *
  9. {@link ACRAConstants#EXTRA_REPORT_FILE_NAME}
  10. + *
  11. {@link ACRAConstants#EXTRA_REPORT_EXCEPTION}
  12. + *
  13. {@link ACRAConstants#EXTRA_REPORT_CONFIG}
  14. + *
  15. {@link ACRAConstants#EXTRA_FORCE_CANCEL} (optional)
  16. *
*/ public abstract class BaseCrashReportDialog extends Activity { @@ -43,51 +43,56 @@ public abstract class BaseCrashReportDialog extends Activity { private ACRAConfiguration config; private Throwable exception; - @CallSuper @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { + protected final void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "CrashReportDialog extras=" + getIntent().getExtras()); - config = (ACRAConfiguration) getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_CONFIG); - if(config == null) { - throw new IllegalStateException("CrashReportDialog has to be called with extra ACRAConstants#EXTRA_REPORT_CONFIG"); + if (ACRA.DEV_LOGGING) { + ACRA.log.d(LOG_TAG, "CrashReportDialog extras=" + getIntent().getExtras()); } + Serializable sConfig = getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_CONFIG); + Serializable sReportFile = getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_FILE); + Serializable sException = getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_EXCEPTION); final boolean forceCancel = getIntent().getBooleanExtra(ACRAConstants.EXTRA_FORCE_CANCEL, false); - if (forceCancel) { - if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Forced reports deletion."); - cancelReports(); + + if (!forceCancel && sConfig instanceof ACRAConfiguration && sReportFile instanceof File + && (sException == null || sException instanceof Throwable)) { + config = (ACRAConfiguration) sConfig; + reportFile = (File) sReportFile; + exception = (Throwable) sException; + init(savedInstanceState); + } else { + if (forceCancel) { + if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Forced reports deletion."); + cancelReports(); + } else { + ACRA.log.w(LOG_TAG, "Illegal or incomplete call of BaseCrashReportDialog."); + } finish(); - return; } + } - reportFile = (File) getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_FILE); - if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Opening CrashReportDialog for " + reportFile); - if (reportFile == null) { - throw new IllegalStateException("CrashReportDialog has to be called with extra ACRAConstants#EXTRA_REPORT_FILE"); - } - exception = (Throwable) getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_EXCEPTION); + protected void init(@Nullable Bundle savedInstanceState) { } /** * Cancel any pending crash reports. */ - @CallSuper - protected void cancelReports() { + protected final void cancelReports() { new BulkReportDeleter(getApplicationContext()).deleteReports(false, 0); } /** * Send crash report given user's comment and email address. If none should be empty strings - * @param comment Comment (may be null) provided by the user. - * @param userEmail Email address (may be null) provided by the client. + * + * @param comment Comment (may be null) provided by the user. + * @param userEmail Email address (may be null) provided by the client. */ - @CallSuper - protected void sendCrash(@Nullable String comment, @Nullable String userEmail) { + protected final void sendCrash(@Nullable String comment, @Nullable String userEmail) { final CrashReportPersister persister = new CrashReportPersister(); try { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Add user comment to " + reportFile); @@ -110,11 +115,11 @@ protected void sendCrash(@Nullable String comment, @Nullable String userEmail) { } } - protected final ACRAConfiguration getConfig(){ + protected final ACRAConfiguration getConfig() { return config; } - protected final Throwable getException(){ + protected final Throwable getException() { return exception; } } diff --git a/src/main/java/org/acra/dialog/CrashReportDialog.java b/src/main/java/org/acra/dialog/CrashReportDialog.java index e68cbd43a5..5f664d233b 100644 --- a/src/main/java/org/acra/dialog/CrashReportDialog.java +++ b/src/main/java/org/acra/dialog/CrashReportDialog.java @@ -40,9 +40,7 @@ public class CrashReportDialog extends BaseCrashReportDialog implements DialogIn @CallSuper @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - + protected void init(@Nullable Bundle savedInstanceState) { scrollable = new LinearLayout(this); scrollable.setOrientation(LinearLayout.VERTICAL); sharedPreferencesFactory = new SharedPreferencesFactory(getApplicationContext(), getConfig()); @@ -64,9 +62,9 @@ protected void buildAndShowDialog(@Nullable Bundle savedInstanceState){ if (iconResourceId != ACRAConstants.DEFAULT_RES_VALUE) { dialogBuilder.setIcon(iconResourceId); } - dialogBuilder.setView(buildCustomView(savedInstanceState)); - dialogBuilder.setPositiveButton(getText(getConfig().resDialogPositiveButtonText()), CrashReportDialog.this); - dialogBuilder.setNegativeButton(getText(getConfig().resDialogNegativeButtonText()), CrashReportDialog.this); + dialogBuilder.setView(buildCustomView(savedInstanceState)) + .setPositiveButton(getText(getConfig().resDialogPositiveButtonText()), this) + .setNegativeButton(getText(getConfig().resDialogNegativeButtonText()), this); mDialog = dialogBuilder.create(); mDialog.setCanceledOnTouchOutside(false);