Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations #389

Merged
merged 1 commit into from
Mar 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/org/acra/ACRA.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static void init(@NonNull Application app) {
* @param config ACRAConfiguration to manually set up ACRA configuration.
* @throws IllegalStateException if it is called more than once.
*/
public static void init(@NonNull Application app, ACRAConfiguration config) {
public static void init(@NonNull Application app, @NonNull ACRAConfiguration config) {
init(app, config, true);
}

Expand Down Expand Up @@ -270,6 +270,7 @@ private static boolean isACRASenderServiceProcess(@NonNull Application app) {
return (processName != null) && processName.endsWith(ACRA_PRIVATE_PROCESS_NAME);
}

@Nullable
private static String getCurrentProcessName(@NonNull Application app) {
final int processId = android.os.Process.myPid();
final ActivityManager manager = (ActivityManager) app.getSystemService(Context.ACTIVITY_SERVICE);
Expand Down Expand Up @@ -321,6 +322,7 @@ private static boolean shouldDisableACRA(@NonNull SharedPreferences prefs) {
* @deprecated since 4.8.0 use {@link SharedPreferencesFactory} instead.
*/
@SuppressWarnings( "unused" )
@NonNull
public static SharedPreferences getACRASharedPreferences() {
return new SharedPreferencesFactory(mApplication, configProxy).create();
}
Expand All @@ -331,7 +333,7 @@ public static SharedPreferences getACRASharedPreferences() {
* @return Current ACRA {@link ReportsCrashes} configuration instance.
* @deprecated since 4.8.0 {@link ACRAConfiguration} should be passed into classes instead of retrieved statically.
*/
@Nullable
@NonNull
@SuppressWarnings( "unused" )
public static ACRAConfiguration getConfig() {
if (mApplication == null) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/acra/ACRAConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package org.acra;

import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;

import org.acra.dialog.CrashReportDialog;

import static org.acra.ReportField.*;
Expand Down Expand Up @@ -103,12 +106,16 @@ public final class ACRAConstants {

public static final int DEFAULT_SHARED_PREFERENCES_MODE = Context.MODE_PRIVATE;

@DrawableRes
public static final int DEFAULT_NOTIFICATION_ICON = android.R.drawable.stat_notify_error;

@DrawableRes
public static final int DEFAULT_DIALOG_ICON = android.R.drawable.ic_dialog_alert;

@StringRes
public static final int DEFAULT_DIALOG_POSITIVE_BUTTON_TEXT = android.R.string.ok;

@StringRes
public static final int DEFAULT_DIALOG_NEGATIVE_BUTTON_TEXT = android.R.string.cancel;

public static final int DEFAULT_RES_VALUE = 0;
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/org/acra/ErrorReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public void initializeExceptionHandler(ErrorReporter reporter) {
* @param enabled Whether this ErrorReporter should capture Exceptions and forward their reports.
* @param listenForUncaughtExceptions Whether to listen for uncaught Exceptions.
*/
ErrorReporter(Application context, @NonNull ACRAConfiguration config, SharedPreferences prefs, boolean enabled, boolean supportedAndroidVersion, boolean listenForUncaughtExceptions) {
ErrorReporter(@NonNull Application context, @NonNull ACRAConfiguration config, @NonNull SharedPreferences prefs,
boolean enabled, boolean supportedAndroidVersion, boolean listenForUncaughtExceptions) {

this.context = context;
this.config = config;
Expand Down Expand Up @@ -131,8 +132,8 @@ public void initializeExceptionHandler(ErrorReporter reporter) {
*/
@Deprecated
@SuppressWarnings("unused")
public void addCustomData(String key, String value) {
crashReportDataFactory.putCustomData(key, value);
public void addCustomData(@NonNull String key, String value) {
putCustomData(key, value);
}

/**
Expand All @@ -155,7 +156,7 @@ public void addCustomData(String key, String value) {
* @see #getCustomData(String)
*/
@SuppressWarnings("unused")
public String putCustomData(String key, String value) {
public String putCustomData(@NonNull String key, String value) {
return crashReportDataFactory.putCustomData(key, value);
}

Expand Down Expand Up @@ -207,7 +208,7 @@ public void initializeExceptionHandler(ErrorReporter reporter) {
* @see #getCustomData(String)
*/
@SuppressWarnings("unused")
public String removeCustomData(String key) {
public String removeCustomData(@NonNull String key) {
return crashReportDataFactory.removeCustomData(key);
}

Expand All @@ -229,7 +230,7 @@ public void clearCustomData() {
* @see #removeCustomData(String)
*/
@SuppressWarnings("unused")
public String getCustomData(String key) {
public String getCustomData(@NonNull String key) {
return crashReportDataFactory.getCustomData(key);
}

Expand All @@ -241,7 +242,7 @@ public String getCustomData(String key) {
* .Thread, java.lang.Throwable)
*/
@Override
public void uncaughtException(Thread t, @NonNull Throwable e) {
public void uncaughtException(@Nullable Thread t, @NonNull Throwable e) {

// If we're not enabled then just pass the Exception on to the defaultExceptionHandler.
if (!reportExecutor.isEnabled()) {
Expand Down Expand Up @@ -275,7 +276,7 @@ public void uncaughtException(Thread t, @NonNull Throwable e) {
* @param e The {@link Throwable} to be reported. If null the report will
* contain a new Exception("Report requested by developer").
*/
public void handleSilentException(Throwable e) {
public void handleSilentException(@Nullable Throwable e) {
performDeprecatedReportPriming();
new ReportBuilder()
.exception(e)
Expand Down Expand Up @@ -330,7 +331,7 @@ public void checkReportsOnApplicationStart() {
* sending the report.
*/
@SuppressWarnings("unused")
public void handleException(Throwable e, boolean endApplication) {
public void handleException(@Nullable Throwable e, boolean endApplication) {
performDeprecatedReportPriming();
final ReportBuilder builder = new ReportBuilder();
builder.exception(e);
Expand All @@ -350,7 +351,7 @@ public void handleException(Throwable e, boolean endApplication) {
* contain a new Exception("Report requested by developer").
*/
@SuppressWarnings("unused")
public void handleException(Throwable e) {
public void handleException(@Nullable Throwable e) {
handleException(e, false);
}

Expand All @@ -366,6 +367,7 @@ private void performDeprecatedReportPriming() {
}
}

@NonNull
private static ReportPrimer getReportPrimer(@NonNull ACRAConfiguration config) {
//noinspection TryWithIdenticalCatches
try {
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/org/acra/annotation/ReportsCrashes.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;

import org.acra.ACRA;
import org.acra.ACRAConstants;
Expand Down Expand Up @@ -95,68 +97,68 @@
* @return Resource id for the label of positive button in the crash dialog.
* If not provided, defaults to 'OK'.
*/
int resDialogPositiveButtonText() default ACRAConstants.DEFAULT_DIALOG_POSITIVE_BUTTON_TEXT;
@StringRes int resDialogPositiveButtonText() default ACRAConstants.DEFAULT_DIALOG_POSITIVE_BUTTON_TEXT;

/**
* @return Resource id for the label of negative button in the crash dialog.
* If not provided, defaults to 'cancel'.
*/
int resDialogNegativeButtonText() default ACRAConstants.DEFAULT_DIALOG_NEGATIVE_BUTTON_TEXT;
@StringRes int resDialogNegativeButtonText() default ACRAConstants.DEFAULT_DIALOG_NEGATIVE_BUTTON_TEXT;

/**
* @return Resource id for the user comment input label in the crash dialog.
* If not provided, disables the input field.
*/
int resDialogCommentPrompt() default ACRAConstants.DEFAULT_RES_VALUE;
@StringRes int resDialogCommentPrompt() default ACRAConstants.DEFAULT_RES_VALUE;

/**
* @return Resource id for the user email address input label in the crash
* dialog. If not provided, disables the input field.
*/
int resDialogEmailPrompt() default ACRAConstants.DEFAULT_RES_VALUE;
@StringRes int resDialogEmailPrompt() default ACRAConstants.DEFAULT_RES_VALUE;

/**
* @return Resource id for the icon in the crash dialog. Default value is
* the system alert icon.
*/
int resDialogIcon() default ACRAConstants.DEFAULT_DIALOG_ICON;
@DrawableRes int resDialogIcon() default ACRAConstants.DEFAULT_DIALOG_ICON;

/**
* @return Resource id for the Toast text triggered when the user accepts to
* send a report in the crash dialog.
*/
int resDialogOkToast() default ACRAConstants.DEFAULT_RES_VALUE;
@StringRes int resDialogOkToast() default ACRAConstants.DEFAULT_RES_VALUE;

/**
* @return Resource id for the text in the crash dialog.
*/
int resDialogText() default ACRAConstants.DEFAULT_RES_VALUE;
@StringRes int resDialogText() default ACRAConstants.DEFAULT_RES_VALUE;

/**
* @return Resource id for the title in the crash dialog.
*/
int resDialogTitle() default ACRAConstants.DEFAULT_RES_VALUE;
@StringRes int resDialogTitle() default ACRAConstants.DEFAULT_RES_VALUE;

/**
* @return Resource id for the icon in the status bar notification. Default
* is the system error notification icon.
*/
int resNotifIcon() default ACRAConstants.DEFAULT_NOTIFICATION_ICON;
@DrawableRes int resNotifIcon() default ACRAConstants.DEFAULT_NOTIFICATION_ICON;

/**
* @return Resource id for the text in the status bar notification.
*/
int resNotifText() default ACRAConstants.DEFAULT_RES_VALUE;
@StringRes int resNotifText() default ACRAConstants.DEFAULT_RES_VALUE;

/**
* @return Resource id for the ticker text in the status bar notification.
*/
int resNotifTickerText() default ACRAConstants.DEFAULT_RES_VALUE;
@StringRes int resNotifTickerText() default ACRAConstants.DEFAULT_RES_VALUE;

/**
* @return Resource id for the title in the status bar notification.
*/
int resNotifTitle() default ACRAConstants.DEFAULT_RES_VALUE;
@StringRes int resNotifTitle() default ACRAConstants.DEFAULT_RES_VALUE;

/**
* Resource id for the Toast text triggered when the application crashes if
Expand All @@ -170,7 +172,7 @@
* @return Resource id for the Toast text triggered when the application
* crashes.
*/
int resToastText() default ACRAConstants.DEFAULT_RES_VALUE;
@StringRes int resToastText() default ACRAConstants.DEFAULT_RES_VALUE;

/**
* @return Name of the SharedPreferences that will host ACRA settings you
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/acra/builder/ReportBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.acra.builder;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -28,11 +29,12 @@ public final class ReportBuilder {
*/
@NonNull
@SuppressWarnings( "unused" )
public ReportBuilder message(String msg) {
public ReportBuilder message(@Nullable String msg) {
message = msg;
return this;
}

@Nullable
public String getMessage() {
return message;
}
Expand All @@ -44,11 +46,12 @@ public String getMessage() {
* @return the updated {@code ReportBuilder}
*/
@NonNull
public ReportBuilder uncaughtExceptionThread(Thread thread) {
public ReportBuilder uncaughtExceptionThread(@Nullable Thread thread) {
uncaughtExceptionThread = thread;
return this;
}

@Nullable
public Thread getUncaughtExceptionThread() {
return uncaughtExceptionThread;
}
Expand All @@ -60,11 +63,12 @@ public Thread getUncaughtExceptionThread() {
* @return the updated {@code ReportBuilder}
*/
@NonNull
public ReportBuilder exception(Throwable e) {
public ReportBuilder exception(@Nullable Throwable e) {
exception = e;
return this;
}

@Nullable
public Throwable getException() {
return exception;
}
Expand Down Expand Up @@ -93,7 +97,7 @@ public ReportBuilder customData(@NonNull Map<String, String> customData) {
*/
@NonNull
@SuppressWarnings("unused")
public ReportBuilder customData(String key, String value) {
public ReportBuilder customData(@NonNull String key, String value) {
customData.put(key, value);
return this;
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/acra/builder/ReportExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.widget.Toast;

import org.acra.ACRA;
import org.acra.ACRAConstants;
import org.acra.ReportingInteractionMode;
Expand Down Expand Up @@ -61,7 +62,8 @@ public final class ReportExecutor {
*/
private static int mNotificationCounter = 0;

public ReportExecutor(Context context, ACRAConfiguration config, CrashReportDataFactory crashReportDataFactory, LastActivityManager lastActivityManager, Thread.UncaughtExceptionHandler defaultExceptionHandler, ReportPrimer reportPrimer) {
public ReportExecutor(@NonNull Context context,@NonNull ACRAConfiguration config,@NonNull CrashReportDataFactory crashReportDataFactory,
@NonNull LastActivityManager lastActivityManager,@Nullable Thread.UncaughtExceptionHandler defaultExceptionHandler,@NonNull ReportPrimer reportPrimer) {
this.context = context;
this.config = config;
this.crashReportDataFactory = crashReportDataFactory;
Expand Down Expand Up @@ -89,7 +91,7 @@ public long getElapsedTime() {
}
}

public void handReportToDefaultExceptionHandler(Thread t, @NonNull Throwable e) {
public void handReportToDefaultExceptionHandler(@Nullable Thread t, @NonNull Throwable e) {
if (defaultExceptionHandler != null) {
ACRA.log.i(LOG_TAG, "ACRA is disabled for " + context.getPackageName()
+ " - forwarding uncaught Exception on to default ExceptionHandler");
Expand Down Expand Up @@ -320,7 +322,7 @@ private void startSendingReports(boolean onlySendSilentReports, boolean approveR
*
* @param reportFile Report file to send.
*/
private void createNotification(File reportFile, @NonNull ReportBuilder reportBuilder) {
private void createNotification(@NonNull File reportFile, @NonNull ReportBuilder reportBuilder) {

final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

Expand Down Expand Up @@ -406,7 +408,7 @@ private void saveCrashReportFile(@NonNull File file, @NonNull CrashReportData cr
* @param reportBuilder ReportBuilder containing the details of the crash.
*/
@NonNull
private Intent createCrashReportDialogIntent(File reportFile, @NonNull ReportBuilder reportBuilder) {
private Intent createCrashReportDialogIntent(@NonNull File reportFile, @NonNull ReportBuilder reportBuilder) {
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Creating DialogIntent for " + reportFile + " exception=" + reportBuilder.getException());
final Intent dialogIntent = new Intent(context, config.reportDialogClass());
dialogIntent.putExtra(ACRAConstants.EXTRA_REPORT_FILE, reportFile);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/acra/collector/ConfigurationCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private ConfigurationCollector() {
* @return A String describing all the fields of the given Configuration,
* with values replaced by constant names.
*/
@NonNull
private String toString(@NonNull Configuration conf) {
final StringBuilder result = new StringBuilder();
for (final Field f : conf.getClass().getFields()) {
Expand Down Expand Up @@ -197,6 +198,7 @@ private String getFieldValueName(@NonNull Configuration conf, @NonNull Field f)
* @return The names of the different values contained in the bitfield,
* separated by '+'.
*/
@NonNull
private static String activeFlags(@NonNull SparseArray<String> valueNames, int bitfield) {
final StringBuilder result = new StringBuilder();

Expand All @@ -222,6 +224,7 @@ private static String activeFlags(@NonNull SparseArray<String> valueNames, int b
* @param context Context for the application being reported.
* @return A String representation of the current configuration for the application.
*/
@NonNull
public static String collectConfiguration(@NonNull Context context) {
try {
final ConfigurationCollector collector = new ConfigurationCollector();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/acra/collector/CrashReportData.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public CrashReportData() {
* @param key the name of the property to find.
* @return the named property value, or {@code null} if it can't be found.
*/
public String getProperty(ReportField key) {
public String getProperty(@NonNull ReportField key) {
return super.get(key);
}

Expand Down
Loading