Skip to content

Commit

Permalink
Remove annotation config (#856)
Browse files Browse the repository at this point in the history
* remove annotation config

* remove annotation test

* fix tests

* fix tests

* add required annotations
  • Loading branch information
F43nd1r authored Dec 10, 2021
1 parent de43050 commit 545e368
Show file tree
Hide file tree
Showing 74 changed files with 1,085 additions and 2,979 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018
* Copyright (c) 2021
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,63 +14,58 @@
* limitations under the License.
*/

package org.acra.annotation;
package org.acra.config

import android.app.job.JobInfo;

import java.lang.annotation.*;
import android.app.job.JobInfo
import com.faendir.kotlin.autodsl.AutoDsl
import org.acra.annotation.AcraDsl
import org.acra.ktx.plus

/**
* @author F43nd1r
* @since 18.04.18
*/
@Deprecated
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Configuration
public @interface AcraScheduler {
String EXTRA_APP_RESTARTED = "acra.restarted";
@AutoDsl(dslMarker = AcraDsl::class)
class SchedulerConfiguration(
/**
* enables this plugin
*/
val enabled: Boolean = true,
/**
* Network constraint for report sending
*
* @return networkType required to allow report sending
* @since 5.2.0
*/
int requiresNetworkType() default JobInfo.NETWORK_TYPE_NONE;
val requiresNetworkType: Int = JobInfo.NETWORK_TYPE_NONE,

/**
* Charging constraint for report sending
*
* @return if reports should only be sent while charging
* @since 5.2.0
*/
boolean requiresCharging() default false;
val requiresCharging: Boolean = false,

/**
* Idle constraint for report sending
*
* @return if reports should only be sent while the device is idle
* @since 5.2.0
*/
boolean requiresDeviceIdle() default false;
val requiresDeviceIdle: Boolean = false,

/**
* Battery constraint for report sending
*
* @return if reports should only be sent while battery isn't low
* @since 5.2.0
*/
boolean requiresBatteryNotLow() default false;
val requiresBatteryNotLow: Boolean = false,

/**
* Restarts the last activity immediately after a crash.
* If an activity is restarted, the {@link org.acra.annotation.AcraScheduler#EXTRA_APP_RESTARTED} extra will contain a boolean true.
* If an activity is restarted, the [org.acra.scheduler.RestartingAdministrator.EXTRA_ACTIVITY_RESTART_AFTER_CRASH] extra will contain a boolean true.
* Note that this might interact badly with the crash dialog.
*
* @return if acra should attempt to restart the app after a crash
* @since 5.2.0
*/
boolean restartAfterCrash() default false;
val restartAfterCrash: Boolean = false,
) : Configuration {
override fun enabled(): Boolean = enabled
}

fun CoreConfigurationBuilder.scheduler(initializer: SchedulerConfigurationBuilder.() -> Unit) {
pluginConfigurations += SchedulerConfigurationBuilder().apply(initializer).build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import android.app.job.JobInfo
import android.content.Context
import android.os.Build
import com.google.auto.service.AutoService
import org.acra.config.ConfigUtils.getPluginConfiguration
import org.acra.config.CoreConfiguration
import org.acra.config.SchedulerConfiguration
import org.acra.config.getPluginConfiguration
import org.acra.plugins.HasConfigPlugin

/**
Expand All @@ -31,12 +31,13 @@ import org.acra.plugins.HasConfigPlugin
* @since 18.04.18
*/
class AdvancedSenderScheduler private constructor(context: Context, config: CoreConfiguration) : DefaultSenderScheduler(context, config) {
private val schedulerConfiguration: SchedulerConfiguration = getPluginConfiguration(config, SchedulerConfiguration::class.java)
private val schedulerConfiguration: SchedulerConfiguration = config.getPluginConfiguration()
override fun configureJob(job: JobInfo.Builder) {
job.setRequiredNetworkType(schedulerConfiguration.requiresNetworkType)
job.setRequiresCharging(schedulerConfiguration.requiresCharging)
job.setRequiresDeviceIdle(schedulerConfiguration.requiresDeviceIdle)
var constrained = schedulerConfiguration.requiresNetworkType != JobInfo.NETWORK_TYPE_NONE || schedulerConfiguration.requiresCharging || schedulerConfiguration.requiresDeviceIdle
var constrained =
schedulerConfiguration.requiresNetworkType != JobInfo.NETWORK_TYPE_NONE || schedulerConfiguration.requiresCharging || schedulerConfiguration.requiresDeviceIdle
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
job.setRequiresBatteryNotLow(schedulerConfiguration.requiresBatteryNotLow)
constrained = constrained or schedulerConfiguration.requiresBatteryNotLow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import android.content.Context
import android.os.PersistableBundle
import com.google.auto.service.AutoService
import org.acra.builder.LastActivityManager
import org.acra.config.ConfigUtils.getPluginConfiguration
import org.acra.config.CoreConfiguration
import org.acra.config.ReportingAdministrator
import org.acra.config.SchedulerConfiguration
import org.acra.config.getPluginConfiguration
import org.acra.log.debug
import org.acra.log.info
import org.acra.log.warn
Expand All @@ -39,7 +39,7 @@ import org.acra.plugins.HasConfigPlugin
class RestartingAdministrator : HasConfigPlugin(SchedulerConfiguration::class.java), ReportingAdministrator {
override fun shouldFinishActivity(context: Context, config: CoreConfiguration, lastActivityManager: LastActivityManager): Boolean {
debug { "RestartingAdministrator entry" }
if (getPluginConfiguration(config, SchedulerConfiguration::class.java).restartAfterCrash) {
if (config.getPluginConfiguration<SchedulerConfiguration>().restartAfterCrash) {
val activity = lastActivityManager.lastActivity
if (activity != null) {
debug { "Try to schedule last activity (" + activity.javaClass.name + ") for restart" }
Expand Down
4 changes: 2 additions & 2 deletions acra-core/src/androidTest/java/org/acra/ACRATest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public class ACRATest {
@Test
public void init() {
Application application = ApplicationProvider.getApplicationContext();
CoreConfigurationBuilder builder = new CoreConfigurationBuilder(application).setPluginLoader(new SimplePluginLoader(StacktraceCollector.class, TestAdministrator.class));
CoreConfigurationBuilder builder = new CoreConfigurationBuilder().withPluginLoader(new SimplePluginLoader(StacktraceCollector.class, TestAdministrator.class));
ACRA.init(application, builder);
ACRA.getErrorReporter().handleException(new RuntimeException());
}

@Test(expected = AssertionError.class)
public void failing() {
Application application = ApplicationProvider.getApplicationContext();
CoreConfigurationBuilder builder = new CoreConfigurationBuilder(application).setPluginLoader(new SimplePluginLoader(FailingTestAdministrator.class));
CoreConfigurationBuilder builder = new CoreConfigurationBuilder().withPluginLoader(new SimplePluginLoader(FailingTestAdministrator.class));
ACRA.init(application, builder);
ACRA.getErrorReporter().handleException(new RuntimeException());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

package org.acra.attachment;

import android.app.Application;
import android.net.Uri;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.acra.config.CoreConfigurationBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -41,7 +38,7 @@ public class DefaultAttachmentProviderTest {
@Test
public void getAttachments() throws Exception {
Uri uri = Uri.parse("content://not-a-valid-content-uri");
List<Uri> result = new DefaultAttachmentProvider().getAttachments(ApplicationProvider.getApplicationContext(), new CoreConfigurationBuilder(new Application()).withAttachmentUris(uri.toString()).build());
List<Uri> result = new DefaultAttachmentProvider().getAttachments(ApplicationProvider.getApplicationContext(), new CoreConfigurationBuilder().withAttachmentUris(uri.toString()).build());
assertThat(result, hasSize(1));
assertEquals(uri, result.get(0));
}
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion acra-core/src/main/java/org/acra/ACRA.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object ACRA {
*/
@JvmOverloads
@JvmStatic
fun init(app: Application, builder: CoreConfigurationBuilder = CoreConfigurationBuilder(app), checkReportsOnApplicationStart: Boolean = true) {
fun init(app: Application, builder: CoreConfigurationBuilder = CoreConfigurationBuilder(), checkReportsOnApplicationStart: Boolean = true) {
try {
init(app, builder.build(), checkReportsOnApplicationStart)
} catch (e: ACRAConfigurationException) {
Expand Down
2 changes: 1 addition & 1 deletion acra-core/src/main/java/org/acra/ACRAConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object ACRAConstants {
* [org.acra.annotation.AcraCore.reportContent].
*/
@JvmField
val DEFAULT_REPORT_FIELDS = arrayOf(ReportField.REPORT_ID, ReportField.APP_VERSION_CODE, ReportField.APP_VERSION_NAME, ReportField.PACKAGE_NAME, ReportField.FILE_PATH,
val DEFAULT_REPORT_FIELDS = listOf(ReportField.REPORT_ID, ReportField.APP_VERSION_CODE, ReportField.APP_VERSION_NAME, ReportField.PACKAGE_NAME, ReportField.FILE_PATH,
ReportField.PHONE_MODEL, ReportField.BRAND, ReportField.PRODUCT, ReportField.ANDROID_VERSION, ReportField.BUILD, ReportField.TOTAL_MEM_SIZE,
ReportField.AVAILABLE_MEM_SIZE, ReportField.BUILD_CONFIG, ReportField.CUSTOM_DATA, ReportField.IS_SILENT, ReportField.STACK_TRACE, ReportField.INITIAL_CONFIGURATION,
ReportField.CRASH_CONFIGURATION, ReportField.DISPLAY, ReportField.USER_COMMENT, ReportField.USER_EMAIL, ReportField.USER_APP_START_DATE, ReportField.USER_CRASH_DATE,
Expand Down
Loading

0 comments on commit 545e368

Please sign in to comment.