-
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 #664 from F43nd1r/scheduler
Advanced scheduling
- Loading branch information
Showing
22 changed files
with
471 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'maven-publish' | ||
apply plugin: 'com.jfrog.bintray' | ||
|
||
dependencies { | ||
api project(':acra-core') | ||
implementation "com.evernote:android-job:$jobVersion" | ||
compileOnly "com.google.auto.service:auto-service:$autoServiceVersion" | ||
annotationProcessor project(':annotationprocessor') | ||
compileOnly project(':annotations') | ||
} |
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,17 @@ | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<manifest package="org.acra.scheduler"/> |
65 changes: 65 additions & 0 deletions
65
acra-advanced-scheduler/src/main/java/org/acra/annotation/AcraScheduler.java
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,65 @@ | ||
/* | ||
* 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.annotation; | ||
|
||
import android.support.annotation.NonNull; | ||
import com.evernote.android.job.JobRequest; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* @author F43nd1r | ||
* @since 18.04.18 | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@Inherited | ||
@Configuration | ||
public @interface AcraScheduler { | ||
/** | ||
* Network constraint for report sending | ||
* | ||
* @return networkType required to allow report sending | ||
* @since 5.2.0 | ||
*/ | ||
@NonNull JobRequest.NetworkType requiresNetworkType() default JobRequest.NetworkType.ANY; | ||
|
||
/** | ||
* Charging constraint for report sending | ||
* | ||
* @return if reports should only be sent while charging | ||
* @since 5.2.0 | ||
*/ | ||
boolean requiresCharging() default 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; | ||
|
||
/** | ||
* 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; | ||
} |
94 changes: 94 additions & 0 deletions
94
acra-advanced-scheduler/src/main/java/org/acra/scheduler/AdvancedSenderScheduler.java
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,94 @@ | ||
/* | ||
* 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.content.Context; | ||
import android.support.annotation.NonNull; | ||
import com.evernote.android.job.Job; | ||
import com.evernote.android.job.JobManager; | ||
import com.evernote.android.job.JobRequest; | ||
import com.evernote.android.job.util.support.PersistableBundleCompat; | ||
import com.google.auto.service.AutoService; | ||
import org.acra.config.ConfigUtils; | ||
import org.acra.config.CoreConfiguration; | ||
import org.acra.config.SchedulerConfiguration; | ||
import org.acra.file.ReportLocator; | ||
import org.acra.plugins.ConfigBasedAllowsDisablePlugin; | ||
import org.acra.sender.SenderService; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Utilizes evernotes android-job to delay report sending | ||
* | ||
* @author F43nd1r | ||
* @since 18.04.18 | ||
*/ | ||
public class AdvancedSenderScheduler implements SenderScheduler { | ||
static final String TAG = "org.acra.report.Job"; | ||
private final Context context; | ||
private final CoreConfiguration config; | ||
|
||
private AdvancedSenderScheduler(@NonNull Context context, @NonNull CoreConfiguration config) { | ||
this.context = context; | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public void scheduleReportSending(boolean onlySendSilentReports) { | ||
if(new ReportLocator(context).getApprovedReports().length == 0) { | ||
return; | ||
} | ||
SchedulerConfiguration schedulerConfiguration = ConfigUtils.getPluginConfiguration(config, SchedulerConfiguration.class); | ||
PersistableBundleCompat extras = new PersistableBundleCompat(); | ||
extras.putBoolean(SenderService.EXTRA_ONLY_SEND_SILENT_REPORTS, onlySendSilentReports); | ||
new JobRequest.Builder(TAG) | ||
.setExecutionWindow(1, TimeUnit.MINUTES.toMillis(1)) | ||
.setExtras(extras) | ||
.setRequirementsEnforced(true) | ||
.setRequiredNetworkType(schedulerConfiguration.requiresNetworkType()) | ||
.setRequiresCharging(schedulerConfiguration.requiresCharging()) | ||
.setRequiresDeviceIdle(schedulerConfiguration.requiresDeviceIdle()) | ||
.setRequiresBatteryNotLow(schedulerConfiguration.requiresBatteryNotLow()) | ||
.setUpdateCurrent(true) | ||
.build() | ||
.schedule(); | ||
} | ||
|
||
@AutoService(SenderSchedulerFactory.class) | ||
public static class Factory extends ConfigBasedAllowsDisablePlugin implements SenderSchedulerFactory { | ||
|
||
public Factory() { | ||
super(SchedulerConfiguration.class); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public SenderScheduler create(@NonNull Context context, @NonNull CoreConfiguration config) { | ||
JobManager.create(context).addJobCreator(tag -> TAG.equals(tag) ? new Job() { | ||
@NonNull | ||
@Override | ||
protected Result onRunJob(@NonNull Params params) { | ||
boolean sendOnlySilentReports = params.getExtras().getBoolean(SenderService.EXTRA_ONLY_SEND_SILENT_REPORTS, false); | ||
new DefaultSenderScheduler(getContext(), config).scheduleReportSending(sendOnlySilentReports); | ||
return Result.SUCCESS; | ||
} | ||
} : null); | ||
return new AdvancedSenderScheduler(context, config); | ||
} | ||
} | ||
} |
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
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
16 changes: 16 additions & 0 deletions
16
acra-core/src/main/java/org/acra/plugins/AllowsDisablePlugin.java
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
16 changes: 16 additions & 0 deletions
16
acra-core/src/main/java/org/acra/plugins/ConfigBasedAllowsDisablePlugin.java
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
Oops, something went wrong.