-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #813 from ACRA/issue_810
Deprecate annotations and improve kotlin dsl configuration. Migrate to kotlin
- Loading branch information
Showing
289 changed files
with
9,890 additions
and
13,459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 0 additions & 75 deletions
75
acra-advanced-scheduler/src/main/java/org/acra/scheduler/AdvancedSenderScheduler.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
acra-advanced-scheduler/src/main/java/org/acra/scheduler/AdvancedSenderScheduler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2018 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.acra.scheduler | ||
|
||
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.plugins.HasConfigPlugin | ||
|
||
/** | ||
* Utilizes jobservice to delay report sending | ||
* | ||
* @author F43nd1r | ||
* @since 18.04.18 | ||
*/ | ||
class AdvancedSenderScheduler private constructor(context: Context, config: CoreConfiguration) : DefaultSenderScheduler(context, config) { | ||
private val schedulerConfiguration: SchedulerConfiguration = getPluginConfiguration(config, SchedulerConfiguration::class.java) | ||
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 | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
job.setRequiresBatteryNotLow(schedulerConfiguration.requiresBatteryNotLow) | ||
constrained = constrained or schedulerConfiguration.requiresBatteryNotLow | ||
} | ||
if (!constrained) { | ||
job.setOverrideDeadline(0) | ||
} | ||
} | ||
|
||
@AutoService(SenderSchedulerFactory::class) | ||
class Factory : HasConfigPlugin(SchedulerConfiguration::class.java), SenderSchedulerFactory { | ||
override fun create(context: Context, config: CoreConfiguration): SenderScheduler { | ||
return AdvancedSenderScheduler(context, config) | ||
} | ||
} | ||
|
||
} |
74 changes: 0 additions & 74 deletions
74
acra-advanced-scheduler/src/main/java/org/acra/scheduler/RestartingAdministrator.java
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
acra-advanced-scheduler/src/main/java/org/acra/scheduler/RestartingAdministrator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2018 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.acra.scheduler | ||
|
||
import android.app.job.JobInfo | ||
import android.app.job.JobScheduler | ||
import android.content.ComponentName | ||
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.log.debug | ||
import org.acra.log.info | ||
import org.acra.log.warn | ||
import org.acra.plugins.HasConfigPlugin | ||
|
||
/** | ||
* @author F43nd1r | ||
* @since 07.05.18 | ||
*/ | ||
@AutoService(ReportingAdministrator::class) | ||
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) { | ||
val activity = lastActivityManager.lastActivity | ||
if (activity != null) { | ||
debug { "Try to schedule last activity (" + activity.javaClass.name + ") for restart" } | ||
try { | ||
val scheduler = (context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler) | ||
val extras = PersistableBundle() | ||
extras.putString(EXTRA_LAST_ACTIVITY, activity.javaClass.name) | ||
scheduler.schedule(JobInfo.Builder(1, ComponentName(context, RestartingService::class.java)) | ||
.setExtras(extras) | ||
.setOverrideDeadline(100) | ||
.build()) | ||
debug { "Successfully scheduled last activity (" + activity.javaClass.name + ") for restart" } | ||
} catch (e: Exception) { | ||
warn(e) { "Failed to schedule last activity for restart" } | ||
} | ||
} else { | ||
info { "Activity restart is enabled but no activity was found. Nothing to do." } | ||
} | ||
} | ||
return true | ||
} | ||
|
||
companion object { | ||
const val EXTRA_LAST_ACTIVITY = "lastActivity" | ||
const val EXTRA_ACTIVITY_RESTART_AFTER_CRASH = "restartAfterCrash" | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
acra-advanced-scheduler/src/main/java/org/acra/scheduler/RestartingService.java
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
acra-advanced-scheduler/src/main/java/org/acra/scheduler/RestartingService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.acra.scheduler | ||
|
||
import android.app.Activity | ||
import android.app.job.JobParameters | ||
import android.app.job.JobService | ||
import android.content.Intent | ||
import org.acra.log.debug | ||
import org.acra.log.warn | ||
|
||
/** | ||
* @author Lukas | ||
* @since 31.12.2018 | ||
*/ | ||
class RestartingService : JobService() { | ||
override fun onStartJob(params: JobParameters): Boolean { | ||
val className = params.extras.getString(RestartingAdministrator.EXTRA_LAST_ACTIVITY) | ||
debug { "Restarting activity $className..." } | ||
if (className != null) { | ||
try { | ||
@Suppress("UNCHECKED_CAST") val activityClass = Class.forName(className) as Class<out Activity> | ||
val intent = Intent(this, activityClass) | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
intent.putExtra(RestartingAdministrator.EXTRA_ACTIVITY_RESTART_AFTER_CRASH, true) | ||
startActivity(intent) | ||
debug { "$className was successfully restarted" } | ||
} catch (e: ClassNotFoundException) { | ||
warn(e) { "Unable to find activity class$className" } | ||
} | ||
} | ||
return false | ||
} | ||
|
||
override fun onStopJob(params: JobParameters): Boolean { | ||
return false | ||
} | ||
} |
Oops, something went wrong.