From 23efe4bffd0502a552dd190e664bc94293b2f0bb Mon Sep 17 00:00:00 2001 From: F43nd1r Date: Sun, 13 Mar 2016 02:43:42 +0100 Subject: [PATCH] annotations --- src/main/java/org/acra/ACRA.java | 6 +- src/main/java/org/acra/ACRAConstants.java | 7 + src/main/java/org/acra/ErrorReporter.java | 22 +- .../org/acra/annotation/ReportsCrashes.java | 28 +- .../java/org/acra/builder/ReportBuilder.java | 12 +- .../java/org/acra/builder/ReportExecutor.java | 10 +- .../collector/ConfigurationCollector.java | 3 + .../org/acra/collector/CrashReportData.java | 2 +- .../collector/CrashReportDataFactory.java | 20 +- .../collector/DeviceFeaturesCollector.java | 1 + .../collector/DisplayManagerCollector.java | 3 +- .../collector/MediaCodecListCollector.java | 2 +- .../org/acra/collector/SettingsCollector.java | 2 +- .../collector/SharedPreferencesCollector.java | 2 +- .../org/acra/config/ACRAConfiguration.java | 345 +++++++++--------- .../org/acra/config/ConfigurationBuilder.java | 148 +++++--- .../acra/dialog/BaseCrashReportDialog.java | 4 +- .../org/acra/dialog/CrashReportDialog.java | 2 +- .../java/org/acra/file/BulkReportDeleter.java | 2 +- .../java/org/acra/file/ReportLocator.java | 7 +- .../ActivityLifecycleCallbacksWrapper.java | 18 +- .../ApplicationHelper.java | 14 +- .../java/org/acra/legacy/ReportMigrator.java | 2 +- .../acra/prefs/SharedPreferencesFactory.java | 4 +- .../org/acra/sender/EmailIntentSender.java | 2 +- .../acra/sender/EmailIntentSenderFactory.java | 2 +- src/main/java/org/acra/sender/HttpSender.java | 8 +- .../org/acra/sender/HttpSenderFactory.java | 2 +- src/main/java/org/acra/sender/NullSender.java | 2 +- .../org/acra/sender/ReportDistributor.java | 4 +- .../java/org/acra/sender/ReportSender.java | 4 +- .../org/acra/sender/ReportSenderFactory.java | 2 +- .../java/org/acra/sender/SenderService.java | 2 +- .../org/acra/sender/SenderServiceStarter.java | 4 +- .../util/ApplicationStartupProcessor.java | 3 +- src/main/java/org/acra/util/HttpRequest.java | 10 +- src/main/java/org/acra/util/Installation.java | 15 +- .../java/org/acra/util/JSONReportBuilder.java | 1 + .../org/acra/util/PackageManagerWrapper.java | 11 +- src/main/java/org/acra/util/ReportUtils.java | 5 + src/main/java/org/acra/util/ToastSender.java | 12 +- src/test/java/org/acra/log/NonAndroidLog.java | 2 +- 42 files changed, 421 insertions(+), 336 deletions(-) diff --git a/src/main/java/org/acra/ACRA.java b/src/main/java/org/acra/ACRA.java index c929dc67a4..55e8c84cd2 100644 --- a/src/main/java/org/acra/ACRA.java +++ b/src/main/java/org/acra/ACRA.java @@ -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); } @@ -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); @@ -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(); } @@ -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) { diff --git a/src/main/java/org/acra/ACRAConstants.java b/src/main/java/org/acra/ACRAConstants.java index b99379eee7..aae54966c5 100644 --- a/src/main/java/org/acra/ACRAConstants.java +++ b/src/main/java/org/acra/ACRAConstants.java @@ -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.*; @@ -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; diff --git a/src/main/java/org/acra/ErrorReporter.java b/src/main/java/org/acra/ErrorReporter.java index 84b405a6e1..4adaab8659 100644 --- a/src/main/java/org/acra/ErrorReporter.java +++ b/src/main/java/org/acra/ErrorReporter.java @@ -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; @@ -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); } /** @@ -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); } @@ -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); } @@ -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); } @@ -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()) { @@ -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) @@ -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); @@ -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); } @@ -366,6 +367,7 @@ private void performDeprecatedReportPriming() { } } + @NonNull private static ReportPrimer getReportPrimer(@NonNull ACRAConfiguration config) { //noinspection TryWithIdenticalCatches try { diff --git a/src/main/java/org/acra/annotation/ReportsCrashes.java b/src/main/java/org/acra/annotation/ReportsCrashes.java index e568ce185d..a45a0bec8f 100644 --- a/src/main/java/org/acra/annotation/ReportsCrashes.java +++ b/src/main/java/org/acra/annotation/ReportsCrashes.java @@ -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; @@ -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 @@ -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 diff --git a/src/main/java/org/acra/builder/ReportBuilder.java b/src/main/java/org/acra/builder/ReportBuilder.java index 208cf47731..2526856d87 100644 --- a/src/main/java/org/acra/builder/ReportBuilder.java +++ b/src/main/java/org/acra/builder/ReportBuilder.java @@ -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; @@ -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; } @@ -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; } @@ -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; } @@ -93,7 +97,7 @@ public ReportBuilder customData(@NonNull Map 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; } diff --git a/src/main/java/org/acra/builder/ReportExecutor.java b/src/main/java/org/acra/builder/ReportExecutor.java index 73622a2ab1..69f50ce9a5 100644 --- a/src/main/java/org/acra/builder/ReportExecutor.java +++ b/src/main/java/org/acra/builder/ReportExecutor.java @@ -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; @@ -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; @@ -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"); @@ -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); @@ -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); diff --git a/src/main/java/org/acra/collector/ConfigurationCollector.java b/src/main/java/org/acra/collector/ConfigurationCollector.java index ad797d4e96..60f73126e5 100644 --- a/src/main/java/org/acra/collector/ConfigurationCollector.java +++ b/src/main/java/org/acra/collector/ConfigurationCollector.java @@ -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()) { @@ -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 valueNames, int bitfield) { final StringBuilder result = new StringBuilder(); @@ -222,6 +224,7 @@ private static String activeFlags(@NonNull SparseArray 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(); diff --git a/src/main/java/org/acra/collector/CrashReportData.java b/src/main/java/org/acra/collector/CrashReportData.java index dfa58f9637..3564932eaa 100644 --- a/src/main/java/org/acra/collector/CrashReportData.java +++ b/src/main/java/org/acra/collector/CrashReportData.java @@ -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); } diff --git a/src/main/java/org/acra/collector/CrashReportDataFactory.java b/src/main/java/org/acra/collector/CrashReportDataFactory.java index 3692143c76..cbc04d82af 100644 --- a/src/main/java/org/acra/collector/CrashReportDataFactory.java +++ b/src/main/java/org/acra/collector/CrashReportDataFactory.java @@ -103,9 +103,9 @@ public final class CrashReportDataFactory { private final Calendar appStartDate; private final String initialConfiguration; - public CrashReportDataFactory(Context context, ACRAConfiguration config, - SharedPreferences prefs, Calendar appStartDate, - String initialConfiguration) { + public CrashReportDataFactory(@NonNull Context context, @NonNull ACRAConfiguration config, + @NonNull SharedPreferences prefs, @NonNull Calendar appStartDate, + @Nullable String initialConfiguration) { this.context = context; this.config = config; this.prefs = prefs; @@ -127,7 +127,7 @@ public CrashReportDataFactory(Context context, ACRAConfiguration config, * @param value The value associated to your key. * @return The previous value for this key if there was one, or null. */ - public String putCustomData(String key, String value) { + public String putCustomData(@NonNull String key, String value) { return customParameters.put(key, value); } @@ -137,7 +137,7 @@ public String putCustomData(String key, String value) { * @param key The key of the data to be removed. * @return The value for this key before removal. */ - public String removeCustomData(String key) { + public String removeCustomData(@NonNull String key) { return customParameters.remove(key); } @@ -154,7 +154,7 @@ public void clearCustomData() { * @param key The key of the data to be retrieved. * @return The value for this key. */ - public String getCustomData(String key) { + public String getCustomData(@NonNull String key) { return customParameters.get(key); } @@ -578,7 +578,8 @@ private String createCustomInfoString(@Nullable Map reportCustom return customInfo.toString(); } - private String getStackTrace(@Nullable String msg, Throwable th) { + @NonNull + private String getStackTrace(@Nullable String msg, @Nullable Throwable th) { final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); @@ -599,7 +600,8 @@ private String getStackTrace(@Nullable String msg, Throwable th) { return stacktraceAsString; } - private String getStackTraceHash(Throwable th) { + @NonNull + private String getStackTraceHash(@Nullable Throwable th) { final StringBuilder res = new StringBuilder(); Throwable cause = th; while (cause != null) { @@ -614,7 +616,7 @@ private String getStackTraceHash(Throwable th) { return Integer.toHexString(res.toString().hashCode()); } - @Nullable + @NonNull private Class getBuildConfigClass() throws ClassNotFoundException { final Class configuredBuildConfig = config.buildConfigClass(); if ((configuredBuildConfig != null) && !configuredBuildConfig.equals(Object.class)) { diff --git a/src/main/java/org/acra/collector/DeviceFeaturesCollector.java b/src/main/java/org/acra/collector/DeviceFeaturesCollector.java index bdccfd424f..4ab389275c 100644 --- a/src/main/java/org/acra/collector/DeviceFeaturesCollector.java +++ b/src/main/java/org/acra/collector/DeviceFeaturesCollector.java @@ -31,6 +31,7 @@ */ final class DeviceFeaturesCollector { + @NonNull public static String getFeatures(@NonNull Context ctx) { final StringBuilder result = new StringBuilder(); diff --git a/src/main/java/org/acra/collector/DisplayManagerCollector.java b/src/main/java/org/acra/collector/DisplayManagerCollector.java index fec068b6d9..242eea40e5 100644 --- a/src/main/java/org/acra/collector/DisplayManagerCollector.java +++ b/src/main/java/org/acra/collector/DisplayManagerCollector.java @@ -18,6 +18,7 @@ final class DisplayManagerCollector { final static SparseArray mFlagsNames = new SparseArray(); + @NonNull public static String collectDisplays(@NonNull Context ctx) { final Display[] displays; final StringBuilder result = new StringBuilder(); @@ -170,7 +171,7 @@ private static String collectRealMetrics(@NonNull Display display) { } @NonNull - private static String collectMetrics(String prefix, @NonNull DisplayMetrics metrics) { + private static String collectMetrics(@NonNull String prefix, @NonNull DisplayMetrics metrics) { return prefix + ".density=" + metrics.density + '\n' + prefix + ".densityDpi=" + metrics.densityDpi + '\n' + prefix + ".scaledDensity=x" + metrics.scaledDensity + '\n' diff --git a/src/main/java/org/acra/collector/MediaCodecListCollector.java b/src/main/java/org/acra/collector/MediaCodecListCollector.java index 70f335ed6c..fd30cdf6c5 100644 --- a/src/main/java/org/acra/collector/MediaCodecListCollector.java +++ b/src/main/java/org/acra/collector/MediaCodecListCollector.java @@ -157,7 +157,7 @@ public static String collectMediaCodecList() { */ @NonNull @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - private static String collectCapabilitiesForType(@NonNull final MediaCodecInfo codecInfo, String type){ + private static String collectCapabilitiesForType(@NonNull final MediaCodecInfo codecInfo, @NonNull String type){ final StringBuilder result = new StringBuilder(); final MediaCodecInfo.CodecCapabilities codecCapabilities = codecInfo.getCapabilitiesForType(type); diff --git a/src/main/java/org/acra/collector/SettingsCollector.java b/src/main/java/org/acra/collector/SettingsCollector.java index d2e6a095af..101b1c0924 100644 --- a/src/main/java/org/acra/collector/SettingsCollector.java +++ b/src/main/java/org/acra/collector/SettingsCollector.java @@ -46,7 +46,7 @@ final class SettingsCollector { private final Context context; private final ACRAConfiguration config; - public SettingsCollector(Context context, ACRAConfiguration config) { + public SettingsCollector(@NonNull Context context, @NonNull ACRAConfiguration config) { this.context = context; this.config = config; } diff --git a/src/main/java/org/acra/collector/SharedPreferencesCollector.java b/src/main/java/org/acra/collector/SharedPreferencesCollector.java index 688f532d2f..735e8f6947 100644 --- a/src/main/java/org/acra/collector/SharedPreferencesCollector.java +++ b/src/main/java/org/acra/collector/SharedPreferencesCollector.java @@ -39,7 +39,7 @@ final class SharedPreferencesCollector { private final Context context; private final ACRAConfiguration config; - public SharedPreferencesCollector(Context context, ACRAConfiguration config) { + public SharedPreferencesCollector(@NonNull Context context, @NonNull ACRAConfiguration config) { this.context = context; this.config = config; } diff --git a/src/main/java/org/acra/config/ACRAConfiguration.java b/src/main/java/org/acra/config/ACRAConfiguration.java index 8bce294a53..d9f3d35b8e 100644 --- a/src/main/java/org/acra/config/ACRAConfiguration.java +++ b/src/main/java/org/acra/config/ACRAConfiguration.java @@ -15,8 +15,11 @@ */ package org.acra.config; +import android.os.Build; +import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.StringRes; import org.acra.ACRA; import org.acra.ACRAConstants; @@ -76,18 +79,31 @@ public final class ACRAConfiguration implements Serializable { private Class reportDialogClass; private Class reportPrimerClass; + @StringRes private Integer resDialogPositiveButtonText; + @StringRes private Integer resDialogNegativeButtonText; + @StringRes private Integer resDialogCommentPrompt; + @StringRes private Integer resDialogEmailPrompt; + @DrawableRes private Integer resDialogIcon; + @StringRes private Integer resDialogOkToast; + @StringRes private Integer resDialogText; + @StringRes private Integer resDialogTitle; + @DrawableRes private Integer resNotifIcon; + @StringRes private Integer resNotifText; + @StringRes private Integer resNotifTickerText; + @StringRes private Integer resNotifTitle; + @StringRes private Integer resToastText; private Integer sharedPreferencesMode; private String sharedPreferencesName; @@ -110,9 +126,10 @@ public final class ACRAConfiguration implements Serializable { private Class[] reportSenderFactoryClasses; /** - * @param builder ConfigurationBuilder with which to initialise this {@link ACRAConfiguration}. + * @param builder ConfigurationBuilder with which to initialise this {@link ACRAConfiguration}. */ - ACRAConfiguration(@Nullable ConfigurationBuilder builder) { + ACRAConfiguration(@NonNull ConfigurationBuilder builder) { + //noinspection ConstantConditions (don't rely on annotations alone) if (builder == null) { throw new NullPointerException("A ConfigurationBuilder must be supplied to ACRAConfiguration"); } @@ -198,10 +215,11 @@ public ACRAConfiguration setHttpHeaders(@NonNull Map headers) { * Retrieve HTTP headers defined by the application developer. These should * be added to requests sent by any third-party sender (over HTTP of * course). - * + * * @return A map associating http header names to their values. */ @SuppressWarnings("unused") + @NonNull public Map getHttpHeaders() { return Collections.unmodifiableMap(httpHeaders); } @@ -209,6 +227,7 @@ public Map getHttpHeaders() { /** * @return List of ReportField that ACRA will provide to the server. */ + @NonNull @SuppressWarnings("unused") public List getReportFields() { final ReportField[] customReportFields = customReportContent(); @@ -228,10 +247,8 @@ public List getReportFields() { } /** - * @param additionalDropboxTags - * the additionalDropboxTags to set + * @param additionalDropboxTags the additionalDropboxTags to set * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull @@ -242,10 +259,8 @@ public ACRAConfiguration setAdditionalDropboxTags(String[] additionalDropboxTags } /** - * @param additionalSharedPreferences - * the additionalSharedPreferences to set + * @param additionalSharedPreferences the additionalSharedPreferences to set * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull @@ -256,24 +271,20 @@ public ACRAConfiguration setAdditionalSharedPreferences(String[] additionalShare } /** - * @param connectionTimeout - * the connectionTimeout to set + * @param connectionTimeout the connectionTimeout to set * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setConnectionTimeout(Integer connectionTimeout) { + @SuppressWarnings("unused") + public ACRAConfiguration setConnectionTimeout(@NonNull Integer connectionTimeout) { this.connectionTimeout = connectionTimeout; return this; } /** - * @param customReportContent - * the customReportContent to set + * @param customReportContent the customReportContent to set * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull @@ -284,142 +295,125 @@ public ACRAConfiguration setCustomReportContent(ReportField[] customReportConten } /** - * @param deleteUnapprovedReportsOnApplicationStart - * the deleteUnapprovedReportsOnApplicationStart to set + * @param deleteUnapprovedReportsOnApplicationStart the deleteUnapprovedReportsOnApplicationStart to set * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setDeleteUnapprovedReportsOnApplicationStart(Boolean deleteUnapprovedReportsOnApplicationStart) { + @SuppressWarnings("unused") + public ACRAConfiguration setDeleteUnapprovedReportsOnApplicationStart(@NonNull Boolean deleteUnapprovedReportsOnApplicationStart) { this.deleteUnapprovedReportsOnApplicationStart = deleteUnapprovedReportsOnApplicationStart; return this; } /** - * @param deleteOldUnsentReportsOnApplicationStart When to delete old (unsent) reports on startup. + * @param deleteOldUnsentReportsOnApplicationStart When to delete old (unsent) reports on startup. * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setDeleteOldUnsentReportsOnApplicationStart(Boolean deleteOldUnsentReportsOnApplicationStart) { + @SuppressWarnings("unused") + public ACRAConfiguration setDeleteOldUnsentReportsOnApplicationStart(@NonNull Boolean deleteOldUnsentReportsOnApplicationStart) { this.deleteOldUnsentReportsOnApplicationStart = deleteOldUnsentReportsOnApplicationStart; return this; } /** - * @param dropboxCollectionMinutes - * the dropboxCollectionMinutes to set + * @param dropboxCollectionMinutes the dropboxCollectionMinutes to set * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setDropboxCollectionMinutes(Integer dropboxCollectionMinutes) { + @SuppressWarnings("unused") + public ACRAConfiguration setDropboxCollectionMinutes(@NonNull Integer dropboxCollectionMinutes) { this.dropboxCollectionMinutes = dropboxCollectionMinutes; return this; } /** - * @param forceCloseDialogAfterToast - * the forceCloseDialogAfterToast to set + * @param forceCloseDialogAfterToast the forceCloseDialogAfterToast to set * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setForceCloseDialogAfterToast(Boolean forceCloseDialogAfterToast) { + @SuppressWarnings("unused") + public ACRAConfiguration setForceCloseDialogAfterToast(@NonNull Boolean forceCloseDialogAfterToast) { this.forceCloseDialogAfterToast = forceCloseDialogAfterToast; return this; } /** * Modify the formUri of your backend server receiving reports. - * - * @param formUri formUri to set. - * @return The updated ACRA configuration * + * @param formUri formUri to set. + * @return The updated ACRA configuration * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setFormUri(String formUri) { + @SuppressWarnings("unused") + public ACRAConfiguration setFormUri(@Nullable String formUri) { this.formUri = formUri; return this; } /** - * @param formUriBasicAuthLogin - * the formUriBasicAuthLogin to set + * @param formUriBasicAuthLogin the formUriBasicAuthLogin to set * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setFormUriBasicAuthLogin(String formUriBasicAuthLogin) { + @SuppressWarnings("unused") + public ACRAConfiguration setFormUriBasicAuthLogin(@Nullable String formUriBasicAuthLogin) { this.formUriBasicAuthLogin = formUriBasicAuthLogin; return this; } /** - * @param formUriBasicAuthPassword - * the formUriBasicAuthPassword to set + * @param formUriBasicAuthPassword the formUriBasicAuthPassword to set * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setFormUriBasicAuthPassword(String formUriBasicAuthPassword) { + @SuppressWarnings("unused") + public ACRAConfiguration setFormUriBasicAuthPassword(@Nullable String formUriBasicAuthPassword) { this.formUriBasicAuthPassword = formUriBasicAuthPassword; return this; } /** - * @param includeDropboxSystemTags - * the includeDropboxSystemTags to set + * @param includeDropboxSystemTags the includeDropboxSystemTags to set * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setIncludeDropboxSystemTags(Boolean includeDropboxSystemTags) { + @SuppressWarnings("unused") + public ACRAConfiguration setIncludeDropboxSystemTags(@NonNull Boolean includeDropboxSystemTags) { this.includeDropBoxSystemTags = includeDropboxSystemTags; return this; } /** - * @param logcatArguments - * the logcatArguments to set + * @param logcatArguments the logcatArguments to set * @return The updated ACRA configuration - * * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setLogcatArguments(String[] logcatArguments) { - this.logcatArguments = logcatArguments; + @SuppressWarnings("unused") + public ACRAConfiguration setLogcatArguments(@NonNull String[] logcatArguments) { + this.logcatArguments = copyArray(logcatArguments); return this; } /** * Modify the mailTo of the mail account receiving reports. - * - * @param mailTo mailTo to set. - * @return The updated ACRA configuration * + * @param mailTo mailTo to set. + * @return The updated ACRA configuration * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setMailTo(String mailTo) { + @SuppressWarnings("unused") + public ACRAConfiguration setMailTo(@Nullable String mailTo) { this.mailTo = mailTo; return this; } @@ -427,18 +421,15 @@ public ACRAConfiguration setMailTo(String mailTo) { /** * Change the current {@link ReportingInteractionMode}. You must set * required configuration items first. - * - * @param mode - * the new mode to set. - * @return The updated ACRA configuration - * @throws ACRAConfigurationException - * if a configuration item is missing for this mode. * + * @param mode the new mode to set. + * @return The updated ACRA configuration + * @throws ACRAConfigurationException if a configuration item is missing for this mode. * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setMode(ReportingInteractionMode mode) throws ACRAConfigurationException { + @SuppressWarnings("unused") + public ACRAConfiguration setMode(@NonNull ReportingInteractionMode mode) throws ACRAConfigurationException { this.reportingInteractionMode = mode; checkCrashResources(); return this; @@ -448,8 +439,8 @@ public ACRAConfiguration setMode(ReportingInteractionMode mode) throws ACRAConfi * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setResDialogPositiveButtonText(int resId) { + @SuppressWarnings("unused") + public ACRAConfiguration setResDialogPositiveButtonText(@StringRes int resId) { resDialogPositiveButtonText = resId; return this; } @@ -458,8 +449,8 @@ public ACRAConfiguration setResDialogPositiveButtonText(int resId) { * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setResDialogNegativeButtonText(int resId) { + @SuppressWarnings("unused") + public ACRAConfiguration setResDialogNegativeButtonText(@StringRes int resId) { resDialogNegativeButtonText = resId; return this; } @@ -468,8 +459,8 @@ public ACRAConfiguration setResDialogNegativeButtonText(int resId) { * @deprecated since 4.8.1 - configure using {@link ConfigurationBuilder} instead. ACRAConfiguration will become immutable in the near future. */ @NonNull - @SuppressWarnings( "unused" ) - public ACRAConfiguration setReportDialogClass(Class reportDialogClass) { + @SuppressWarnings("unused") + public ACRAConfiguration setReportDialogClass(@NonNull Class reportDialogClass) { this.reportDialogClass = reportDialogClass; return this; } @@ -478,17 +469,15 @@ public ACRAConfiguration setReportDialogClass(Class[] } @SuppressWarnings("unused") + @NonNull public String[] additionalDropBoxTags() { return additionalDropBoxTags; } @SuppressWarnings("unused") + @NonNull public String[] additionalSharedPreferences() { return additionalSharedPreferences; } @@ -901,6 +865,7 @@ public int connectionTimeout() { return connectionTimeout; } + @NonNull @SuppressWarnings("unused") public ReportField[] customReportContent() { return customReportContent; @@ -927,16 +892,19 @@ public boolean forceCloseDialogAfterToast() { } @SuppressWarnings("unused") + @Nullable public String formUri() { return formUri; } @SuppressWarnings("unused") + @Nullable public String formUriBasicAuthLogin() { return formUriBasicAuthLogin; } @SuppressWarnings("unused") + @Nullable public String formUriBasicAuthPassword() { return formUriBasicAuthPassword; } @@ -947,81 +915,97 @@ public boolean includeDropBoxSystemTags() { } @SuppressWarnings("unused") + @NonNull public String[] logcatArguments() { return logcatArguments; } @SuppressWarnings("unused") + @Nullable public String mailTo() { return mailTo; } @SuppressWarnings("unused") + @NonNull public ReportingInteractionMode mode() { return reportingInteractionMode; } @SuppressWarnings("unused") + @StringRes public int resDialogPositiveButtonText() { return resDialogPositiveButtonText; } @SuppressWarnings("unused") + @StringRes public int resDialogNegativeButtonText() { return resDialogNegativeButtonText; } @SuppressWarnings("unused") + @StringRes public int resDialogCommentPrompt() { return resDialogCommentPrompt; } @SuppressWarnings("unused") + @StringRes public int resDialogEmailPrompt() { return resDialogEmailPrompt; } @SuppressWarnings("unused") + @DrawableRes public int resDialogIcon() { return resDialogIcon; } @SuppressWarnings("unused") + @StringRes public int resDialogOkToast() { return resDialogOkToast; } @SuppressWarnings("unused") + @StringRes public int resDialogText() { return resDialogText; } @SuppressWarnings("unused") + @StringRes public int resDialogTitle() { return resDialogTitle; } @SuppressWarnings("unused") + @DrawableRes public int resNotifIcon() { return resNotifIcon; } @SuppressWarnings("unused") + @StringRes public int resNotifText() { return resNotifText; } @SuppressWarnings("unused") + @StringRes public int resNotifTickerText() { return resNotifTickerText; } @SuppressWarnings("unused") + @StringRes public int resNotifTitle() { return resNotifTitle; } @SuppressWarnings("unused") + @StringRes public int resToastText() { return resToastText; } @@ -1032,6 +1016,7 @@ public int sharedPreferencesMode() { } @SuppressWarnings("unused") + @NonNull public String sharedPreferencesName() { return sharedPreferencesName; } @@ -1056,11 +1041,13 @@ public boolean sendReportsAtShutdown() { return sendReportsAtShutdown; } + @NonNull @SuppressWarnings("unused") public String[] excludeMatchingSharedPreferencesKeys() { return excludeMatchingSharedPreferencesKeys; } + @NonNull @SuppressWarnings("unused") public String[] excludeMatchingSettingsKeys() { return excludeMatchingSettingsKeys; @@ -1077,6 +1064,7 @@ public Class buildConfigClass() { } @SuppressWarnings("unused") + @NonNull public String applicationLogFile() { return applicationLogFile; } @@ -1087,25 +1075,30 @@ public int applicationLogFileLines() { } @SuppressWarnings("unused") + @NonNull public Class reportDialogClass() { return reportDialogClass; } @SuppressWarnings("unused") + @NonNull public Class reportPrimerClass() { return reportPrimerClass; } @SuppressWarnings("unused") + @NonNull public Method httpMethod() { return httpMethod; } @SuppressWarnings("unused") + @NonNull public Type reportType() { return reportType; } + @NonNull @SuppressWarnings("unused") public Class[] reportSenderFactoryClasses() { return reportSenderFactoryClasses; diff --git a/src/main/java/org/acra/config/ConfigurationBuilder.java b/src/main/java/org/acra/config/ConfigurationBuilder.java index 7ccc4cda09..60f91d3e69 100644 --- a/src/main/java/org/acra/config/ConfigurationBuilder.java +++ b/src/main/java/org/acra/config/ConfigurationBuilder.java @@ -16,8 +16,10 @@ package org.acra.config; import android.app.Application; +import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.StringRes; import org.acra.ReportField; import org.acra.ReportingInteractionMode; @@ -71,19 +73,19 @@ public final class ConfigurationBuilder { private Class reportDialogClass; private Class reportPrimerClass; - private Integer resDialogPositiveButtonText; - private Integer resDialogNegativeButtonText; - private Integer resDialogCommentPrompt; - private Integer resDialogEmailPrompt; - private Integer resDialogIcon; - private Integer resDialogOkToast; - private Integer resDialogText; - private Integer resDialogTitle; - private Integer resNotifIcon; - private Integer resNotifText; - private Integer resNotifTickerText; - private Integer resNotifTitle; - private Integer resToastText; + @StringRes private Integer resDialogPositiveButtonText; + @StringRes private Integer resDialogNegativeButtonText; + @StringRes private Integer resDialogCommentPrompt; + @StringRes private Integer resDialogEmailPrompt; + @DrawableRes private Integer resDialogIcon; + @StringRes private Integer resDialogOkToast; + @StringRes private Integer resDialogText; + @StringRes private Integer resDialogTitle; + @DrawableRes private Integer resNotifIcon; + @StringRes private Integer resNotifText; + @StringRes private Integer resNotifTickerText; + @StringRes private Integer resNotifTitle; + @StringRes private Integer resToastText; private Integer sharedPreferencesMode; private String sharedPreferencesName; private Integer socketTimeout; @@ -197,7 +199,7 @@ public ConfigurationBuilder setHttpHeaders(@NonNull Map headers) */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setAdditionalDropboxTags(String[] additionalDropboxTags) { + public ConfigurationBuilder setAdditionalDropboxTags(@NonNull String[] additionalDropboxTags) { this.additionalDropBoxTags = additionalDropboxTags; return this; } @@ -209,7 +211,7 @@ public ConfigurationBuilder setAdditionalDropboxTags(String[] additionalDropboxT */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setAdditionalSharedPreferences(String[] additionalSharedPreferences) { + public ConfigurationBuilder setAdditionalSharedPreferences(@NonNull String[] additionalSharedPreferences) { this.additionalSharedPreferences = additionalSharedPreferences; return this; } @@ -221,7 +223,7 @@ public ConfigurationBuilder setAdditionalSharedPreferences(String[] additionalSh */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setConnectionTimeout(Integer connectionTimeout) { + public ConfigurationBuilder setConnectionTimeout(@NonNull Integer connectionTimeout) { this.connectionTimeout = connectionTimeout; return this; } @@ -233,7 +235,7 @@ public ConfigurationBuilder setConnectionTimeout(Integer connectionTimeout) { */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setCustomReportContent(ReportField[] customReportContent) { + public ConfigurationBuilder setCustomReportContent(@NonNull ReportField[] customReportContent) { this.customReportContent = customReportContent; return this; } @@ -244,7 +246,7 @@ public ConfigurationBuilder setCustomReportContent(ReportField[] customReportCon */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setDeleteUnapprovedReportsOnApplicationStart(Boolean deleteUnapprovedReportsOnApplicationStart) { + public ConfigurationBuilder setDeleteUnapprovedReportsOnApplicationStart(@NonNull Boolean deleteUnapprovedReportsOnApplicationStart) { this.deleteUnapprovedReportsOnApplicationStart = deleteUnapprovedReportsOnApplicationStart; return this; } @@ -255,7 +257,7 @@ public ConfigurationBuilder setDeleteUnapprovedReportsOnApplicationStart(Boolean */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setDeleteOldUnsentReportsOnApplicationStart(Boolean deleteOldUnsentReportsOnApplicationStart) { + public ConfigurationBuilder setDeleteOldUnsentReportsOnApplicationStart(@NonNull Boolean deleteOldUnsentReportsOnApplicationStart) { this.deleteOldUnsentReportsOnApplicationStart = deleteOldUnsentReportsOnApplicationStart; return this; } @@ -267,7 +269,7 @@ public ConfigurationBuilder setDeleteOldUnsentReportsOnApplicationStart(Boolean */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setDropboxCollectionMinutes(Integer dropboxCollectionMinutes) { + public ConfigurationBuilder setDropboxCollectionMinutes(@NonNull Integer dropboxCollectionMinutes) { this.dropboxCollectionMinutes = dropboxCollectionMinutes; return this; } @@ -279,7 +281,7 @@ public ConfigurationBuilder setDropboxCollectionMinutes(Integer dropboxCollectio */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setForceCloseDialogAfterToast(Boolean forceCloseDialogAfterToast) { + public ConfigurationBuilder setForceCloseDialogAfterToast(@NonNull Boolean forceCloseDialogAfterToast) { this.forceCloseDialogAfterToast = forceCloseDialogAfterToast; return this; } @@ -292,7 +294,7 @@ public ConfigurationBuilder setForceCloseDialogAfterToast(Boolean forceCloseDial */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setFormUri(String formUri) { + public ConfigurationBuilder setFormUri(@Nullable String formUri) { this.formUri = formUri; return this; } @@ -304,7 +306,7 @@ public ConfigurationBuilder setFormUri(String formUri) { */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setFormUriBasicAuthLogin(String formUriBasicAuthLogin) { + public ConfigurationBuilder setFormUriBasicAuthLogin(@Nullable String formUriBasicAuthLogin) { this.formUriBasicAuthLogin = formUriBasicAuthLogin; return this; } @@ -316,7 +318,7 @@ public ConfigurationBuilder setFormUriBasicAuthLogin(String formUriBasicAuthLogi */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setFormUriBasicAuthPassword(String formUriBasicAuthPassword) { + public ConfigurationBuilder setFormUriBasicAuthPassword(@Nullable String formUriBasicAuthPassword) { this.formUriBasicAuthPassword = formUriBasicAuthPassword; return this; } @@ -328,7 +330,7 @@ public ConfigurationBuilder setFormUriBasicAuthPassword(String formUriBasicAuthP */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setIncludeDropboxSystemTags(Boolean includeDropboxSystemTags) { + public ConfigurationBuilder setIncludeDropboxSystemTags(@NonNull Boolean includeDropboxSystemTags) { this.includeDropBoxSystemTags = includeDropboxSystemTags; return this; } @@ -340,7 +342,7 @@ public ConfigurationBuilder setIncludeDropboxSystemTags(Boolean includeDropboxSy */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setLogcatArguments(String[] logcatArguments) { + public ConfigurationBuilder setLogcatArguments(@NonNull String[] logcatArguments) { this.logcatArguments = logcatArguments; return this; } @@ -353,7 +355,7 @@ public ConfigurationBuilder setLogcatArguments(String[] logcatArguments) { */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setMailTo(String mailTo) { + public ConfigurationBuilder setMailTo(@Nullable String mailTo) { this.mailTo = mailTo; return this; } @@ -369,7 +371,7 @@ public ConfigurationBuilder setMailTo(String mailTo) { */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setMode(ReportingInteractionMode mode) throws ACRAConfigurationException { + public ConfigurationBuilder setMode(@NonNull ReportingInteractionMode mode) throws ACRAConfigurationException { this.reportingInteractionMode = mode; return this; } @@ -383,28 +385,28 @@ public ConfigurationBuilder setMode(ReportingInteractionMode mode) throws ACRACo */ @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setReportingInteractionMode(ReportingInteractionMode mode) throws ACRAConfigurationException { + public ConfigurationBuilder setReportingInteractionMode(@NonNull ReportingInteractionMode mode) throws ACRAConfigurationException { this.reportingInteractionMode = mode; return this; } @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setResDialogPositiveButtonText(int resId) { + public ConfigurationBuilder setResDialogPositiveButtonText(@StringRes int resId) { resDialogPositiveButtonText = resId; return this; } @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setResDialogNegativeButtonText(int resId) { + public ConfigurationBuilder setResDialogNegativeButtonText(@StringRes int resId) { resDialogNegativeButtonText = resId; return this; } @NonNull @SuppressWarnings( "unused" ) - public ConfigurationBuilder setReportDialogClass(Class reportDialogClass) { + public ConfigurationBuilder setReportDialogClass(@NonNull Class reportDialogClass) { this.reportDialogClass = reportDialogClass; return this; } @@ -419,7 +421,7 @@ public ConfigurationBuilder setReportDialogClass(Class[] reportSenderFactoryClasses) { + public void setReportSenderFactoryClasses(@NonNull Class[] reportSenderFactoryClasses) { this.reportSenderFactoryClasses = reportSenderFactoryClasses; } @SuppressWarnings("unused") - public void setReportPrimerClass(Class reportPrimerClass) { + public void setReportPrimerClass(@NonNull Class reportPrimerClass) { this.reportPrimerClass = reportPrimerClass; } @@ -781,6 +783,7 @@ public void setReportPrimerClass(Class reportPrimerClass // Getters - used to provide values and !DEFAULTS! to ACRConfiguration during construction @SuppressWarnings("unused") + @NonNull String[] additionalDropBoxTags() { if (additionalDropBoxTags != null) { return additionalDropBoxTags; @@ -789,6 +792,7 @@ String[] additionalDropBoxTags() { } @SuppressWarnings("unused") + @NonNull String[] additionalSharedPreferences() { if (additionalSharedPreferences != null) { return additionalSharedPreferences; @@ -814,6 +818,7 @@ int connectionTimeout() { } @SuppressWarnings("unused") + @NonNull ReportField[] customReportContent() { if (customReportContent != null) { return customReportContent; @@ -854,6 +859,7 @@ boolean forceCloseDialogAfterToast() { } @SuppressWarnings("unused") + @NonNull String formUri() { if (formUri != null) { return formUri; @@ -862,6 +868,7 @@ String formUri() { } @SuppressWarnings("unused") + @NonNull String formUriBasicAuthLogin() { if (formUriBasicAuthLogin != null) { return formUriBasicAuthLogin; @@ -870,6 +877,7 @@ String formUriBasicAuthLogin() { } @SuppressWarnings("unused") + @NonNull String formUriBasicAuthPassword() { if (formUriBasicAuthPassword != null) { return formUriBasicAuthPassword; @@ -886,6 +894,7 @@ boolean includeDropBoxSystemTags() { } @SuppressWarnings("unused") + @NonNull String[] logcatArguments() { if (logcatArguments != null) { return logcatArguments; @@ -894,6 +903,7 @@ String[] logcatArguments() { } @SuppressWarnings("unused") + @NonNull String mailTo() { if (mailTo != null) { return mailTo; @@ -902,6 +912,7 @@ String mailTo() { } @SuppressWarnings("unused") + @NonNull ReportingInteractionMode reportingInteractionMode() { if (reportingInteractionMode != null) { return reportingInteractionMode; @@ -910,6 +921,7 @@ ReportingInteractionMode reportingInteractionMode() { } @SuppressWarnings("unused") + @StringRes public int resDialogPositiveButtonText() { if (resDialogPositiveButtonText != null) { return resDialogPositiveButtonText; @@ -918,6 +930,7 @@ public int resDialogPositiveButtonText() { } @SuppressWarnings("unused") + @StringRes int resDialogNegativeButtonText() { if (resDialogNegativeButtonText != null) { return resDialogNegativeButtonText; @@ -926,6 +939,7 @@ int resDialogNegativeButtonText() { } @SuppressWarnings("unused") + @StringRes int resDialogCommentPrompt() { if (resDialogCommentPrompt != null) { return resDialogCommentPrompt; @@ -934,6 +948,7 @@ int resDialogCommentPrompt() { } @SuppressWarnings("unused") + @StringRes int resDialogEmailPrompt() { if (resDialogEmailPrompt != null) { return resDialogEmailPrompt; @@ -942,6 +957,7 @@ int resDialogEmailPrompt() { } @SuppressWarnings("unused") + @DrawableRes int resDialogIcon() { if (resDialogIcon != null) { return resDialogIcon; @@ -950,6 +966,7 @@ int resDialogIcon() { } @SuppressWarnings("unused") + @StringRes int resDialogOkToast() { if (resDialogOkToast != null) { return resDialogOkToast; @@ -958,6 +975,7 @@ int resDialogOkToast() { } @SuppressWarnings("unused") + @StringRes int resDialogText() { if (resDialogText != null) { return resDialogText; @@ -966,6 +984,7 @@ int resDialogText() { } @SuppressWarnings("unused") + @StringRes int resDialogTitle() { if (resDialogTitle != null) { return resDialogTitle; @@ -974,6 +993,7 @@ int resDialogTitle() { } @SuppressWarnings("unused") + @DrawableRes int resNotifIcon() { if (resNotifIcon != null) { return resNotifIcon; @@ -982,6 +1002,7 @@ int resNotifIcon() { } @SuppressWarnings("unused") + @StringRes int resNotifText() { if (resNotifText != null) { return resNotifText; @@ -990,6 +1011,7 @@ int resNotifText() { } @SuppressWarnings("unused") + @StringRes int resNotifTickerText() { if (resNotifTickerText != null) { return resNotifTickerText; @@ -998,6 +1020,7 @@ int resNotifTickerText() { } @SuppressWarnings("unused") + @StringRes int resNotifTitle() { if (resNotifTitle != null) { return resNotifTitle; @@ -1006,6 +1029,7 @@ int resNotifTitle() { } @SuppressWarnings("unused") + @StringRes int resToastText() { if (resToastText != null) { return resToastText; @@ -1022,6 +1046,7 @@ int sharedPreferencesMode() { } @SuppressWarnings("unused") + @NonNull String sharedPreferencesName() { if (sharedPreferencesName != null) { return sharedPreferencesName; @@ -1063,6 +1088,7 @@ boolean sendReportsAtShutdown() { } @SuppressWarnings("unused") + @NonNull String[] excludeMatchingSharedPreferencesKeys() { if (excludeMatchingSharedPreferencesKeys != null) { return excludeMatchingSharedPreferencesKeys; @@ -1071,6 +1097,7 @@ String[] excludeMatchingSharedPreferencesKeys() { } @SuppressWarnings("unused") + @NonNull String[] excludeMatchingSettingsKeys() { if (excludeMatchingSettingsKeys != null) { return excludeMatchingSettingsKeys; @@ -1083,6 +1110,7 @@ String[] excludeMatchingSettingsKeys() { * It is up to clients to construct the recommended default value oof context.getClass().getPackage().getName() + BuildConfig.class */ @SuppressWarnings("unused") + @Nullable Class buildConfigClass() { if (buildConfigClass != null) { return buildConfigClass; @@ -1091,6 +1119,7 @@ Class buildConfigClass() { } @SuppressWarnings("unused") + @NonNull String applicationLogFile() { if (applicationLogFile != null) { return applicationLogFile; @@ -1107,6 +1136,7 @@ int applicationLogFileLines() { } @SuppressWarnings("unused") + @NonNull Class reportDialogClass() { if (reportDialogClass != null) { return reportDialogClass; @@ -1115,6 +1145,7 @@ Class reportDialogClass() { } @SuppressWarnings("unused") + @NonNull Class reportPrimerClass() { if (reportPrimerClass != null) { return reportPrimerClass; @@ -1123,6 +1154,7 @@ Class reportPrimerClass() { } @SuppressWarnings("unused") + @NonNull Method httpMethod() { if (httpMethod != null) { return httpMethod; @@ -1131,6 +1163,7 @@ Method httpMethod() { } @SuppressWarnings("unused") + @NonNull Type reportType() { if (reportType != null) { return reportType; @@ -1139,6 +1172,7 @@ Type reportType() { } @SuppressWarnings("unused") + @NonNull Class[] reportSenderFactoryClasses() { if (reportSenderFactoryClasses != null) { return reportSenderFactoryClasses; diff --git a/src/main/java/org/acra/dialog/BaseCrashReportDialog.java b/src/main/java/org/acra/dialog/BaseCrashReportDialog.java index 1705c78d3c..59763696d0 100644 --- a/src/main/java/org/acra/dialog/BaseCrashReportDialog.java +++ b/src/main/java/org/acra/dialog/BaseCrashReportDialog.java @@ -43,7 +43,7 @@ public abstract class BaseCrashReportDialog extends Activity { @CallSuper @Override - protected void onCreate(Bundle savedInstanceState) { + protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "CrashReportDialog extras=" + getIntent().getExtras()); @@ -69,6 +69,7 @@ protected void onCreate(Bundle savedInstanceState) { /** * Cancel any pending crash reports. */ + @CallSuper protected void cancelReports() { new BulkReportDeleter(getApplicationContext()).deleteReports(false, 0); } @@ -79,6 +80,7 @@ protected void cancelReports() { * @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) { final CrashReportPersister persister = new CrashReportPersister(); try { diff --git a/src/main/java/org/acra/dialog/CrashReportDialog.java b/src/main/java/org/acra/dialog/CrashReportDialog.java index 985f444fdf..f533a2e848 100644 --- a/src/main/java/org/acra/dialog/CrashReportDialog.java +++ b/src/main/java/org/acra/dialog/CrashReportDialog.java @@ -120,7 +120,7 @@ protected View buildCustomView(@Nullable Bundle savedInstanceState) { * * @param v the view to add */ - protected final void addViewToDialog(View v) { + protected final void addViewToDialog(@NonNull View v) { scrollable.addView(v); } diff --git a/src/main/java/org/acra/file/BulkReportDeleter.java b/src/main/java/org/acra/file/BulkReportDeleter.java index c993f44148..edc9b6b1e7 100644 --- a/src/main/java/org/acra/file/BulkReportDeleter.java +++ b/src/main/java/org/acra/file/BulkReportDeleter.java @@ -18,7 +18,7 @@ public final class BulkReportDeleter { @NonNull private final ReportLocator reportLocator; - public BulkReportDeleter(Context context) { + public BulkReportDeleter(@NonNull Context context) { this.reportLocator = new ReportLocator(context); } diff --git a/src/main/java/org/acra/file/ReportLocator.java b/src/main/java/org/acra/file/ReportLocator.java index 882ef365f9..838a145c46 100644 --- a/src/main/java/org/acra/file/ReportLocator.java +++ b/src/main/java/org/acra/file/ReportLocator.java @@ -1,6 +1,7 @@ package org.acra.file; import android.content.Context; +import android.support.annotation.NonNull; import java.io.File; import java.util.Arrays; @@ -19,14 +20,16 @@ public final class ReportLocator { private final Context context; - public ReportLocator(Context context) { + public ReportLocator(@NonNull Context context) { this.context = context; } + @NonNull public File getUnapprovedFolder() { return context.getDir(UNAPPROVED_FOLDER_NAME, Context.MODE_PRIVATE); } + @NonNull public File[] getUnapprovedReports() { final File[] reports = getUnapprovedFolder().listFiles(); if (reports == null) { @@ -35,6 +38,7 @@ public File[] getUnapprovedReports() { return reports; } + @NonNull public File getApprovedFolder() { return context.getDir(APPROVED_FOLDER_NAME, Context.MODE_PRIVATE); } @@ -42,6 +46,7 @@ public File getApprovedFolder() { /** * @return Approved reports sorted by creation time. */ + @NonNull public File[] getApprovedReports() { final File[] reports = getApprovedFolder().listFiles(); if (reports == null) { diff --git a/src/main/java/org/acra/jraf/android/util/activitylifecyclecallbackscompat/ActivityLifecycleCallbacksWrapper.java b/src/main/java/org/acra/jraf/android/util/activitylifecyclecallbackscompat/ActivityLifecycleCallbacksWrapper.java index fc7a5f2dbe..618a79c52a 100644 --- a/src/main/java/org/acra/jraf/android/util/activitylifecyclecallbackscompat/ActivityLifecycleCallbacksWrapper.java +++ b/src/main/java/org/acra/jraf/android/util/activitylifecyclecallbackscompat/ActivityLifecycleCallbacksWrapper.java @@ -28,6 +28,8 @@ import android.app.Application.ActivityLifecycleCallbacks; import android.os.Build; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; /** * Wraps an {@link ActivityLifecycleCallbacksCompat} into an {@link ActivityLifecycleCallbacks}. @@ -37,42 +39,42 @@ class ActivityLifecycleCallbacksWrapper implements ActivityLifecycleCallbacks { private final ActivityLifecycleCallbacksCompat mCallback; - public ActivityLifecycleCallbacksWrapper(ActivityLifecycleCallbacksCompat callback) { + public ActivityLifecycleCallbacksWrapper(@NonNull ActivityLifecycleCallbacksCompat callback) { mCallback = callback; } @Override - public void onActivityCreated(Activity activity, Bundle savedInstanceState) { + public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { mCallback.onActivityCreated(activity, savedInstanceState); } @Override - public void onActivityStarted(Activity activity) { + public void onActivityStarted(@NonNull Activity activity) { mCallback.onActivityStarted(activity); } @Override - public void onActivityResumed(Activity activity) { + public void onActivityResumed(@NonNull Activity activity) { mCallback.onActivityResumed(activity); } @Override - public void onActivityPaused(Activity activity) { + public void onActivityPaused(@NonNull Activity activity) { mCallback.onActivityPaused(activity); } @Override - public void onActivityStopped(Activity activity) { + public void onActivityStopped(@NonNull Activity activity) { mCallback.onActivityStopped(activity); } @Override - public void onActivitySaveInstanceState(Activity activity, Bundle outState) { + public void onActivitySaveInstanceState(@NonNull Activity activity, Bundle outState) { mCallback.onActivitySaveInstanceState(activity, outState); } @Override - public void onActivityDestroyed(Activity activity) { + public void onActivityDestroyed(@NonNull Activity activity) { mCallback.onActivityDestroyed(activity); } diff --git a/src/main/java/org/acra/jraf/android/util/activitylifecyclecallbackscompat/ApplicationHelper.java b/src/main/java/org/acra/jraf/android/util/activitylifecyclecallbackscompat/ApplicationHelper.java index 5d5d2d7110..a974ef4f10 100644 --- a/src/main/java/org/acra/jraf/android/util/activitylifecyclecallbackscompat/ApplicationHelper.java +++ b/src/main/java/org/acra/jraf/android/util/activitylifecyclecallbackscompat/ApplicationHelper.java @@ -34,19 +34,19 @@ * Helper for accessing {@link Application#registerActivityLifecycleCallbacks(ActivityLifecycleCallbacks)} and * {@link Application#unregisterActivityLifecycleCallbacks(ActivityLifecycleCallbacks)} introduced in API level 14 in a * backwards compatible fashion.
- * + *

* When running on API level 14 or above, the framework's implementations of these methods will be used. */ public final class ApplicationHelper { /** * Registers a callback to be called following the life cycle of the application's {@link Activity activities}. - * + * * @param application The application with which to register the callback. - * @param callback The callback to register. + * @param callback The callback to register. */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) - public static void registerActivityLifecycleCallbacks(@NonNull Application application, ActivityLifecycleCallbacksCompat callback) { + public static void registerActivityLifecycleCallbacks(@NonNull Application application, @NonNull ActivityLifecycleCallbacksCompat callback) { application.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacksWrapper(callback)); } @@ -57,12 +57,12 @@ public static void registerActivityLifecycleCallbacks(@NonNull Application appli /** * Unregisters a previously registered callback. - * + * * @param application The application with which to unregister the callback. - * @param callback The callback to unregister. + * @param callback The callback to unregister. */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) - public void unregisterActivityLifecycleCallbacks(@NonNull Application application, ActivityLifecycleCallbacksCompat callback) { + public void unregisterActivityLifecycleCallbacks(@NonNull Application application, @NonNull ActivityLifecycleCallbacksCompat callback) { application.unregisterActivityLifecycleCallbacks(new ActivityLifecycleCallbacksWrapper(callback)); } } diff --git a/src/main/java/org/acra/legacy/ReportMigrator.java b/src/main/java/org/acra/legacy/ReportMigrator.java index 39dc094097..1277a6a59e 100644 --- a/src/main/java/org/acra/legacy/ReportMigrator.java +++ b/src/main/java/org/acra/legacy/ReportMigrator.java @@ -23,7 +23,7 @@ public final class ReportMigrator { @NonNull private final ReportLocator reportLocator; - public ReportMigrator(Context context) { + public ReportMigrator(@NonNull Context context) { this.context = context; this.reportLocator = new ReportLocator(context); } diff --git a/src/main/java/org/acra/prefs/SharedPreferencesFactory.java b/src/main/java/org/acra/prefs/SharedPreferencesFactory.java index 476826a19c..0ef37d2a5b 100644 --- a/src/main/java/org/acra/prefs/SharedPreferencesFactory.java +++ b/src/main/java/org/acra/prefs/SharedPreferencesFactory.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import android.support.annotation.NonNull; import org.acra.annotation.ReportsCrashes; import org.acra.config.ACRAConfiguration; @@ -20,7 +21,7 @@ public class SharedPreferencesFactory { private final Context context; private final ACRAConfiguration config; - public SharedPreferencesFactory(Context context, ACRAConfiguration config) { + public SharedPreferencesFactory(@NonNull Context context, @NonNull ACRAConfiguration config) { this.context = context; this.config = config; } @@ -28,6 +29,7 @@ public SharedPreferencesFactory(Context context, ACRAConfiguration config) { /** * @return The Shared Preferences where ACRA will retrieve its user adjustable setting. */ + @NonNull public SharedPreferences create() { if (context == null) { throw new IllegalStateException("Cannot call ACRA.getACRASharedPreferences() before ACRA.init()."); diff --git a/src/main/java/org/acra/sender/EmailIntentSender.java b/src/main/java/org/acra/sender/EmailIntentSender.java index 05def30094..35a07a71bd 100644 --- a/src/main/java/org/acra/sender/EmailIntentSender.java +++ b/src/main/java/org/acra/sender/EmailIntentSender.java @@ -44,7 +44,7 @@ public EmailIntentSender(Context ctx, ACRAConfiguration config) { } @Override - public void send(Context context, @NonNull CrashReportData errorContent) throws ReportSenderException { + public void send(@NonNull Context context, @NonNull CrashReportData errorContent) throws ReportSenderException { final String subject = mContext.getPackageName() + " Crash Report"; final String body = buildBody(errorContent); diff --git a/src/main/java/org/acra/sender/EmailIntentSenderFactory.java b/src/main/java/org/acra/sender/EmailIntentSenderFactory.java index 66e75937ca..1426cf308e 100644 --- a/src/main/java/org/acra/sender/EmailIntentSenderFactory.java +++ b/src/main/java/org/acra/sender/EmailIntentSenderFactory.java @@ -12,7 +12,7 @@ public final class EmailIntentSenderFactory implements ReportSenderFactory { @NonNull @Override - public ReportSender create(Context context, ACRAConfiguration config) { + public ReportSender create(@NonNull Context context, @NonNull ACRAConfiguration config) { return new EmailIntentSender(context, config); } } diff --git a/src/main/java/org/acra/sender/HttpSender.java b/src/main/java/org/acra/sender/HttpSender.java index 3c14fe1089..bfcfd2548c 100644 --- a/src/main/java/org/acra/sender/HttpSender.java +++ b/src/main/java/org/acra/sender/HttpSender.java @@ -133,7 +133,7 @@ public String getContentType() { * parameters will be named with the result of * mapping.get(ReportField.SOME_FIELD); */ - public HttpSender(ACRAConfiguration config, Method method, Type type, Map mapping) { + public HttpSender(@NonNull ACRAConfiguration config, @NonNull Method method, @NonNull Type type, @Nullable Map mapping) { this(config, method, type, null, mapping); } @@ -163,7 +163,7 @@ public HttpSender(ACRAConfiguration config, Method method, Type type, Map mapping) { + public HttpSender(@NonNull ACRAConfiguration config, @NonNull Method method, @NonNull Type type, @Nullable String formUri, @Nullable Map mapping) { this.config = config; mMethod = method; mFormUri = (formUri == null) ? null : Uri.parse(formUri); @@ -185,13 +185,13 @@ public HttpSender(ACRAConfiguration config, Method method, Type type, @Nullable * The password to set for HTTP Basic Auth. */ @SuppressWarnings( "unused" ) - public void setBasicAuth(String username, String password) { + public void setBasicAuth(@Nullable String username, @Nullable String password) { mUsername = username; mPassword = password; } @Override - public void send(Context context, @NonNull CrashReportData report) throws ReportSenderException { + public void send(@NonNull Context context, @NonNull CrashReportData report) throws ReportSenderException { try { URL reportUrl = mFormUri == null ? new URL(config.formUri()) : new URL(mFormUri.toString()); diff --git a/src/main/java/org/acra/sender/HttpSenderFactory.java b/src/main/java/org/acra/sender/HttpSenderFactory.java index b466287fb6..b08726353c 100644 --- a/src/main/java/org/acra/sender/HttpSenderFactory.java +++ b/src/main/java/org/acra/sender/HttpSenderFactory.java @@ -12,7 +12,7 @@ public final class HttpSenderFactory implements ReportSenderFactory { @NonNull @Override - public ReportSender create(Context context, @NonNull ACRAConfiguration config) { + public ReportSender create(@NonNull Context context, @NonNull ACRAConfiguration config) { return new HttpSender(config, config.httpMethod(), config.reportType(), null); } } diff --git a/src/main/java/org/acra/sender/NullSender.java b/src/main/java/org/acra/sender/NullSender.java index 2876a3dd5e..a3539c066b 100644 --- a/src/main/java/org/acra/sender/NullSender.java +++ b/src/main/java/org/acra/sender/NullSender.java @@ -13,7 +13,7 @@ */ final class NullSender implements ReportSender { @Override - public void send(@NonNull Context context, CrashReportData errorContent) throws ReportSenderException { + public void send(@NonNull Context context, @NonNull CrashReportData errorContent) throws ReportSenderException { ACRA.log.w(LOG_TAG, context.getPackageName() + " reports will NOT be sent - no valid ReportSender is configured. Try setting 'formUri' or 'mailTo'"); } } diff --git a/src/main/java/org/acra/sender/ReportDistributor.java b/src/main/java/org/acra/sender/ReportDistributor.java index ab4eba9419..09822d84a7 100644 --- a/src/main/java/org/acra/sender/ReportDistributor.java +++ b/src/main/java/org/acra/sender/ReportDistributor.java @@ -50,7 +50,7 @@ final class ReportDistributor { * @param config Configuration to use while sending. * @param reportSenders List of ReportSender to use to send the crash reports. */ - public ReportDistributor(Context context, ACRAConfiguration config, List reportSenders) { + public ReportDistributor(@NonNull Context context, @NonNull ACRAConfiguration config, @NonNull List reportSenders) { this.context = context; this.config = config; this.reportSenders = reportSenders; @@ -91,7 +91,7 @@ public void distribute(@NonNull File reportFile) { * @param errorContent Crash data. * @throws ReportSenderException if unable to send the crash report. */ - private void sendCrashReport(CrashReportData errorContent) throws ReportSenderException { + private void sendCrashReport(@NonNull CrashReportData errorContent) throws ReportSenderException { if (!isDebuggable() || config.sendReportsInDevMode()) { boolean sentAtLeastOnce = false; ReportSenderException sendFailure = null; diff --git a/src/main/java/org/acra/sender/ReportSender.java b/src/main/java/org/acra/sender/ReportSender.java index 30e06369e7..06a56e628b 100644 --- a/src/main/java/org/acra/sender/ReportSender.java +++ b/src/main/java/org/acra/sender/ReportSender.java @@ -16,6 +16,8 @@ package org.acra.sender; import android.content.Context; +import android.support.annotation.NonNull; + import org.acra.collector.CrashReportData; /** @@ -44,5 +46,5 @@ public interface ReportSender { * data, you can (should) throw a {@link ReportSenderException} * with a custom message. */ - void send(Context context, CrashReportData errorContent) throws ReportSenderException; + void send(@NonNull Context context, @NonNull CrashReportData errorContent) throws ReportSenderException; } diff --git a/src/main/java/org/acra/sender/ReportSenderFactory.java b/src/main/java/org/acra/sender/ReportSenderFactory.java index 47e23029fb..122abb2e79 100644 --- a/src/main/java/org/acra/sender/ReportSenderFactory.java +++ b/src/main/java/org/acra/sender/ReportSenderFactory.java @@ -21,5 +21,5 @@ public interface ReportSenderFactory { * @return Fully configured instance of the relevant ReportSender. */ @NonNull - ReportSender create(Context context, ACRAConfiguration config); + ReportSender create(@NonNull Context context, @NonNull ACRAConfiguration config); } diff --git a/src/main/java/org/acra/sender/SenderService.java b/src/main/java/org/acra/sender/SenderService.java index e9e4f72363..f5a748325a 100644 --- a/src/main/java/org/acra/sender/SenderService.java +++ b/src/main/java/org/acra/sender/SenderService.java @@ -76,7 +76,7 @@ protected void onHandleIntent(@NonNull final Intent intent) { } @NonNull - private List getSenderInstances(ACRAConfiguration config, @NonNull List> factoryClasses) { + private List getSenderInstances(@NonNull ACRAConfiguration config, @NonNull List> factoryClasses) { final List reportSenders = new ArrayList(); for (final Class factoryClass : factoryClasses) { //noinspection TryWithIdenticalCatches diff --git a/src/main/java/org/acra/sender/SenderServiceStarter.java b/src/main/java/org/acra/sender/SenderServiceStarter.java index ac3421cb9a..bcfb9fd200 100644 --- a/src/main/java/org/acra/sender/SenderServiceStarter.java +++ b/src/main/java/org/acra/sender/SenderServiceStarter.java @@ -2,6 +2,8 @@ import android.content.Context; import android.content.Intent; +import android.support.annotation.NonNull; + import org.acra.ACRA; import org.acra.config.ACRAConfiguration; @@ -18,7 +20,7 @@ public class SenderServiceStarter { private final Context context; private final ACRAConfiguration config; - public SenderServiceStarter(Context context, ACRAConfiguration config) { + public SenderServiceStarter(@NonNull Context context, @NonNull ACRAConfiguration config) { this.context = context; this.config = config; } diff --git a/src/main/java/org/acra/util/ApplicationStartupProcessor.java b/src/main/java/org/acra/util/ApplicationStartupProcessor.java index 3c4390c72a..46350a31ef 100644 --- a/src/main/java/org/acra/util/ApplicationStartupProcessor.java +++ b/src/main/java/org/acra/util/ApplicationStartupProcessor.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageInfo; +import android.support.annotation.NonNull; import android.widget.Toast; import org.acra.ACRA; import org.acra.ReportingInteractionMode; @@ -24,7 +25,7 @@ public final class ApplicationStartupProcessor { private final Context context; private final ACRAConfiguration config; - public ApplicationStartupProcessor(Context context, ACRAConfiguration config) { + public ApplicationStartupProcessor(@NonNull Context context, @NonNull ACRAConfiguration config) { this.context = context; this.config = config; } diff --git a/src/main/java/org/acra/util/HttpRequest.java b/src/main/java/org/acra/util/HttpRequest.java index d2a4dc21dd..387addfef5 100644 --- a/src/main/java/org/acra/util/HttpRequest.java +++ b/src/main/java/org/acra/util/HttpRequest.java @@ -7,6 +7,7 @@ import android.content.Context; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.util.Base64; import org.acra.ACRA; @@ -39,15 +40,15 @@ public final class HttpRequest { private int socketTimeOut = 3000; private Map headers; - public HttpRequest(ACRAConfiguration config) { + public HttpRequest(@NonNull ACRAConfiguration config) { this.config = config; } - public void setLogin(String login) { + public void setLogin(@Nullable String login) { this.login = login; } - public void setPassword(String password) { + public void setPassword(@Nullable String password) { this.password = password; } @@ -59,7 +60,7 @@ public void setSocketTimeOut(int socketTimeOut) { this.socketTimeOut = socketTimeOut; } - public void setHeaders(Map headers) { + public void setHeaders(@Nullable Map headers) { this.headers = headers; } @@ -166,6 +167,7 @@ public void send(@NonNull Context context, @NonNull URL url, @NonNull Method met * @return URL encoded String representing the parameters. * @throws UnsupportedEncodingException if one of the parameters couldn't be converted to UTF-8. */ + @NonNull public static String getParamsAsFormString(@NonNull Map parameters) throws UnsupportedEncodingException { final StringBuilder dataBfr = new StringBuilder(); diff --git a/src/main/java/org/acra/util/Installation.java b/src/main/java/org/acra/util/Installation.java index 38da1696bd..571f3b12b6 100644 --- a/src/main/java/org/acra/util/Installation.java +++ b/src/main/java/org/acra/util/Installation.java @@ -4,17 +4,17 @@ */ package org.acra.util; +import android.content.Context; +import android.support.annotation.NonNull; + +import org.acra.ACRA; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.RandomAccessFile; import java.util.UUID; -import org.acra.ACRA; - -import android.content.Context; -import android.support.annotation.NonNull; - import static org.acra.ACRA.LOG_TAG; /** @@ -33,7 +33,8 @@ public class Installation { private static String sID; private static final String INSTALLATION = "ACRA-INSTALLATION"; - public synchronized static String id(@NonNull Context context) { + @NonNull + public static synchronized String id(@NonNull Context context) { if (sID == null) { final File installation = new File(context.getFilesDir(), INSTALLATION); try { @@ -53,7 +54,7 @@ public synchronized static String id(@NonNull Context context) { } @NonNull - private static String readInstallationFile(File installation) throws IOException { + private static String readInstallationFile(@NonNull File installation) throws IOException { final RandomAccessFile f = new RandomAccessFile(installation, "r"); final byte[] bytes = new byte[(int) f.length()]; try { diff --git a/src/main/java/org/acra/util/JSONReportBuilder.java b/src/main/java/org/acra/util/JSONReportBuilder.java index cbeac5f536..549318b799 100644 --- a/src/main/java/org/acra/util/JSONReportBuilder.java +++ b/src/main/java/org/acra/util/JSONReportBuilder.java @@ -159,6 +159,7 @@ private static void addJSONFromProperty(@NonNull JSONObject destination, @NonNul } } + @NonNull private static Object guessType(@NonNull String value) { if (value.equalsIgnoreCase("true")) return true; diff --git a/src/main/java/org/acra/util/PackageManagerWrapper.java b/src/main/java/org/acra/util/PackageManagerWrapper.java index fa31c70830..fc582d4bf7 100644 --- a/src/main/java/org/acra/util/PackageManagerWrapper.java +++ b/src/main/java/org/acra/util/PackageManagerWrapper.java @@ -1,13 +1,15 @@ package org.acra.util; -import static org.acra.ACRA.LOG_TAG; - import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import org.acra.ACRA; +import static org.acra.ACRA.LOG_TAG; + /** * Responsible for wrapping calls to PackageManager to ensure that they always complete without throwing RuntimeExceptions. *

@@ -28,7 +30,7 @@ public final class PackageManagerWrapper { private final Context context; - public PackageManagerWrapper(Context context) { + public PackageManagerWrapper(@NonNull Context context) { this.context = context; } @@ -36,7 +38,7 @@ public PackageManagerWrapper(Context context) { * @param permission Manifest.permission to check whether it has been granted. * @return true if the permission has been granted to the app, false if it hasn't been granted or the PackageManager could not be contacted. */ - public boolean hasPermission(String permission) { + public boolean hasPermission(@NonNull String permission) { final PackageManager pm = context.getPackageManager(); if (pm == null) { return false; @@ -54,6 +56,7 @@ public boolean hasPermission(String permission) { /** * @return PackageInfo for the current application or null if the PackageManager could not be contacted. */ + @Nullable public PackageInfo getPackageInfo() { final PackageManager pm = context.getPackageManager(); if (pm == null) { diff --git a/src/main/java/org/acra/util/ReportUtils.java b/src/main/java/org/acra/util/ReportUtils.java index 415bb21258..61a8318ecc 100644 --- a/src/main/java/org/acra/util/ReportUtils.java +++ b/src/main/java/org/acra/util/ReportUtils.java @@ -5,6 +5,7 @@ import android.os.Environment; import android.os.StatFs; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.telephony.TelephonyManager; import org.acra.ACRA; import org.acra.ACRAConstants; @@ -82,6 +83,7 @@ public static long getTotalInternalMemorySize() { * @param context Context for the application being reported. * @return Returns the DeviceId according to the TelephonyManager or null if there is no TelephonyManager. */ + @Nullable public static String getDeviceId(@NonNull Context context) { try { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); @@ -92,6 +94,7 @@ public static String getDeviceId(@NonNull Context context) { } } + @NonNull public static String getApplicationFilePath(@NonNull Context context) { final File filesDir = context.getFilesDir(); if (filesDir != null) { @@ -102,6 +105,7 @@ public static String getApplicationFilePath(@NonNull Context context) { return "Couldn't retrieve ApplicationFilePath"; } + @NonNull public static String getLocalIpAddress() { final StringBuilder result = new StringBuilder(); boolean first = true; @@ -125,6 +129,7 @@ public static String getLocalIpAddress() { return result.toString(); } + @NonNull public static String getTimeString(@NonNull Calendar time) { final SimpleDateFormat format = new SimpleDateFormat(ACRAConstants.DATE_TIME_FORMAT_STRING, Locale.ENGLISH); return format.format(time.getTimeInMillis()); diff --git a/src/main/java/org/acra/util/ToastSender.java b/src/main/java/org/acra/util/ToastSender.java index 76295f2b11..6084c1b6da 100644 --- a/src/main/java/org/acra/util/ToastSender.java +++ b/src/main/java/org/acra/util/ToastSender.java @@ -3,6 +3,9 @@ import org.acra.ACRA; import android.content.Context; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.StringRes; import android.widget.Toast; import static org.acra.ACRA.LOG_TAG; @@ -10,6 +13,7 @@ /** * Responsible for sending Toasts under all circumstances. *

+ * * @author William Ferguson * @since 4.3.0 */ @@ -18,11 +22,11 @@ public final class ToastSender { /** * Sends a Toast and ensures that any Exception thrown during sending is handled. * - * @param context Application context. - * @param toastResourceId Id of the resource to send as the Toast message. - * @param toastLength Length of the Toast. + * @param context Application context. + * @param toastResourceId Id of the resource to send as the Toast message. + * @param toastLength Length of the Toast. */ - public static void sendToast(Context context, int toastResourceId, int toastLength) { + public static void sendToast(@NonNull Context context, @StringRes int toastResourceId, @IntRange(from = 0, to = 1) int toastLength) { try { Toast.makeText(context, toastResourceId, toastLength).show(); } catch (RuntimeException e) { diff --git a/src/test/java/org/acra/log/NonAndroidLog.java b/src/test/java/org/acra/log/NonAndroidLog.java index b176cfcbba..28f3f601a6 100644 --- a/src/test/java/org/acra/log/NonAndroidLog.java +++ b/src/test/java/org/acra/log/NonAndroidLog.java @@ -31,7 +31,7 @@ public final class NonAndroidLog implements ACRALog { /** * Any log that is output at level less that the supplied logLevel will be ignored. *

- * The deault log level is {@link NonAndroidLog#VERBOSE} + * The default log level is {@link NonAndroidLog#VERBOSE} *

* * @param logLevel LogLevel to use to filter log output.