mirror of
https://github.com/ACRA/acra.git
synced 2026-03-13 10:09:46 +08:00
Fix mailsender on android Q (#740)
* fix mailsender on android q * update travis.yml * move to stable api * fix travis * fix travis 2 * update robolectric
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
language: android
|
||||
android:
|
||||
components:
|
||||
- build-tools-28.0.2
|
||||
- android-28
|
||||
- build-tools-28.0.3
|
||||
- build-tools-29.0.0
|
||||
- android-29
|
||||
before_cache:
|
||||
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
|
||||
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ReportInteractionExecutor {
|
||||
}
|
||||
boolean sendReports = true;
|
||||
for (Future<Boolean> future : futures) {
|
||||
while (!future.isDone()) {
|
||||
do {
|
||||
try {
|
||||
sendReports &= future.get();
|
||||
} catch (InterruptedException ignored) {
|
||||
@@ -70,7 +70,7 @@ public class ReportInteractionExecutor {
|
||||
//ReportInteraction crashed, so ignore it
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (!future.isDone());
|
||||
}
|
||||
return sendReports;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.support.annotation.NonNull;
|
||||
import org.acra.config.CoreConfiguration;
|
||||
import org.acra.sender.JobSenderService;
|
||||
import org.acra.sender.LegacySenderService;
|
||||
import org.acra.sender.SendingConductor;
|
||||
import org.acra.util.IOUtils;
|
||||
|
||||
/**
|
||||
@@ -46,21 +47,27 @@ public class DefaultSenderScheduler implements SenderScheduler {
|
||||
|
||||
@Override
|
||||
public void scheduleReportSending(boolean onlySendSilentReports) {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(LegacySenderService.EXTRA_ONLY_SEND_SILENT_REPORTS, onlySendSilentReports);
|
||||
intent.putExtra(LegacySenderService.EXTRA_ACRA_CONFIG, config);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||
PersistableBundle extras = new PersistableBundle();
|
||||
extras.putString(LegacySenderService.EXTRA_ACRA_CONFIG, IOUtils.serialize(config));
|
||||
extras.putBoolean(LegacySenderService.EXTRA_ONLY_SEND_SILENT_REPORTS, onlySendSilentReports);
|
||||
assert scheduler != null;
|
||||
JobInfo.Builder builder = new JobInfo.Builder(0, new ComponentName(context, JobSenderService.class)).setOverrideDeadline(0L).setExtras(extras);
|
||||
configureJob(builder);
|
||||
scheduler.schedule(builder.build());
|
||||
} else {
|
||||
intent.setComponent(new ComponentName(context, LegacySenderService.class));
|
||||
context.startService(intent);
|
||||
SendingConductor conductor = new SendingConductor(context, config);
|
||||
if(!conductor.getSenderInstances(false).isEmpty()) {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(LegacySenderService.EXTRA_ONLY_SEND_SILENT_REPORTS, onlySendSilentReports);
|
||||
intent.putExtra(LegacySenderService.EXTRA_ACRA_CONFIG, config);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||
PersistableBundle extras = new PersistableBundle();
|
||||
extras.putString(LegacySenderService.EXTRA_ACRA_CONFIG, IOUtils.serialize(config));
|
||||
extras.putBoolean(LegacySenderService.EXTRA_ONLY_SEND_SILENT_REPORTS, onlySendSilentReports);
|
||||
assert scheduler != null;
|
||||
JobInfo.Builder builder = new JobInfo.Builder(0, new ComponentName(context, JobSenderService.class)).setOverrideDeadline(0L).setExtras(extras);
|
||||
configureJob(builder);
|
||||
scheduler.schedule(builder.build());
|
||||
} else {
|
||||
intent.setComponent(new ComponentName(context, LegacySenderService.class));
|
||||
context.startService(intent);
|
||||
}
|
||||
}
|
||||
if(!conductor.getSenderInstances(true).isEmpty()) {
|
||||
conductor.sendReports(onlySendSilentReports, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class JobSenderService extends JobService {
|
||||
boolean onlySilent = extras.getBoolean(LegacySenderService.EXTRA_ONLY_SEND_SILENT_REPORTS);
|
||||
if (config != null) {
|
||||
new Thread(() -> {
|
||||
new SendingConductor(this, config).sendReports(onlySilent);
|
||||
new SendingConductor(this, config).sendReports(onlySilent, false);
|
||||
jobFinished(params, false);
|
||||
}).start();
|
||||
}
|
||||
|
||||
@@ -34,15 +34,16 @@ public class LegacySenderService extends Service {
|
||||
if (intent.hasExtra(EXTRA_ACRA_CONFIG)) {
|
||||
final boolean onlySendSilentReports = intent.getBooleanExtra(EXTRA_ONLY_SEND_SILENT_REPORTS, false);
|
||||
final CoreConfiguration config = (CoreConfiguration) intent.getSerializableExtra(EXTRA_ACRA_CONFIG);
|
||||
new Thread(() -> {
|
||||
new SendingConductor(this, config).sendReports(onlySendSilentReports);
|
||||
stopSelf();
|
||||
}).start();
|
||||
if (config != null) {
|
||||
new Thread(() -> {
|
||||
new SendingConductor(this, config).sendReports(onlySendSilentReports, false);
|
||||
stopSelf();
|
||||
}).start();
|
||||
}
|
||||
} else {
|
||||
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "SenderService was started but no valid intent was delivered, will now quit");
|
||||
}
|
||||
return START_REDELIVER_INTENT;
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -37,4 +37,8 @@ public interface ReportSender {
|
||||
* @throws ReportSenderException If anything goes fatally wrong during the handling of crash data, you can (should) throw a {@link ReportSenderException} with a custom message.
|
||||
*/
|
||||
void send(@NonNull Context context, @NonNull CrashReportData errorContent) throws ReportSenderException;
|
||||
|
||||
default boolean requiresForeground() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +35,15 @@ public class SendingConductor {
|
||||
locator = new ReportLocator(context);
|
||||
}
|
||||
|
||||
public void sendReports(boolean onlySendSilentReports) {
|
||||
public void sendReports(boolean onlySendSilentReports, boolean foreground) {
|
||||
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "About to start sending reports from SenderService");
|
||||
try {
|
||||
final List<ReportSender> senderInstances = getSenderInstances();
|
||||
final List<ReportSender> senderInstances = getSenderInstances(foreground);
|
||||
|
||||
if (senderInstances.isEmpty()) {
|
||||
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "No ReportSenders configured - adding NullSender");
|
||||
senderInstances.add(new NullSender());
|
||||
}
|
||||
|
||||
// Get approved reports
|
||||
final File[] reports = locator.getApprovedReports();
|
||||
@@ -77,7 +82,7 @@ public class SendingConductor {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private List<ReportSender> getSenderInstances() {
|
||||
public List<ReportSender> getSenderInstances(boolean foreground) {
|
||||
List<Class<? extends ReportSenderFactory>> factoryClasses = config.reportSenderFactoryClasses();
|
||||
|
||||
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "config#reportSenderFactoryClasses : " + factoryClasses);
|
||||
@@ -98,12 +103,9 @@ public class SendingConductor {
|
||||
for (ReportSenderFactory factory : factories) {
|
||||
final ReportSender sender = factory.create(context, config);
|
||||
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Adding reportSender : " + sender);
|
||||
reportSenders.add(sender);
|
||||
}
|
||||
|
||||
if (reportSenders.isEmpty()) {
|
||||
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "No ReportSenders configured - adding NullSender");
|
||||
reportSenders.add(new NullSender());
|
||||
if(foreground == sender.requiresForeground()) {
|
||||
reportSenders.add(sender);
|
||||
}
|
||||
}
|
||||
return reportSenders;
|
||||
}
|
||||
|
||||
@@ -109,6 +109,12 @@ public class EmailIntentSender implements ReportSender {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresForeground() {
|
||||
//TODO make this code Q after Android Q release
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.P;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the package name of the default email client supporting attachments
|
||||
*
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
annotationProcessor "com.google.auto.service:auto-service:$autoServiceVersion"
|
||||
compile "com.google.auto.service:auto-service:$autoServiceVersion"
|
||||
compile "com.google.auto.service:auto-service-annotations:$autoServiceVersion"
|
||||
compile 'com.squareup:javapoet:1.11.1'
|
||||
compile 'org.apache.commons:commons-lang3:3.8.1'
|
||||
compile 'org.apache.commons:commons-text:1.6'
|
||||
|
||||
@@ -89,6 +89,7 @@ subprojects {
|
||||
plugins.withType(LibraryPlugin) {
|
||||
android {
|
||||
compileSdkVersion Integer.parseInt(androidVersion)
|
||||
buildToolsVersion "$buildToolsVersion"
|
||||
defaultConfig {
|
||||
minSdkVersion androidMinVersion
|
||||
targetSdkVersion androidVersion
|
||||
@@ -118,7 +119,7 @@ subprojects {
|
||||
|
||||
dependencies {
|
||||
testImplementation "junit:junit:$junitVersion"
|
||||
testImplementation "org.robolectric:robolectric:$roboelectricVersion"
|
||||
testImplementation "org.robolectric:robolectric:$robolectricVersion"
|
||||
testImplementation "androidx.test:core:$androidTestVersion"
|
||||
}
|
||||
|
||||
|
||||
@@ -29,14 +29,15 @@ group=ch.acra
|
||||
# versions
|
||||
version=5.3.1-SNAPSHOT
|
||||
supportVersion=28.0.0
|
||||
androidVersion=28
|
||||
androidVersion=29
|
||||
androidMinVersion=14
|
||||
androidBuildPluginVersion=3.3.0-alpha10
|
||||
androidBuildPluginVersion=3.4.1
|
||||
buildToolsVersion=29.0.0
|
||||
bintrayPluginVersion=1.8.3
|
||||
releasePluginVersion=2.7.0
|
||||
autoServiceVersion=1.0-rc5
|
||||
junitVersion=4.12
|
||||
roboelectricVersion=4.0.2
|
||||
robolectricVersion=4.3
|
||||
androidTestVersion=1.0.0
|
||||
jobVersion=1.2.6
|
||||
workVersion=1.0.0-alpha12
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3-all.zip
|
||||
|
||||
Reference in New Issue
Block a user