-
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 #667 from F43nd1r/issue_660
Add option to restart last activity after crash
- Loading branch information
Showing
7 changed files
with
181 additions
and
17 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
80 changes: 80 additions & 0 deletions
80
acra-advanced-scheduler/src/main/java/org/acra/scheduler/AcraJobCreator.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,80 @@ | ||
/* | ||
* 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.Activity; | ||
import android.content.Intent; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import com.evernote.android.job.Job; | ||
import com.evernote.android.job.JobCreator; | ||
import org.acra.ACRA; | ||
import org.acra.config.CoreConfiguration; | ||
import org.acra.sender.SenderService; | ||
|
||
/** | ||
* @author F43nd1r | ||
* @since 07.05.18 | ||
*/ | ||
class AcraJobCreator implements JobCreator { | ||
static final String REPORT_TAG = "org.acra.report.Job"; | ||
static final String RESTART_TAG = "org.acra.restart.Job"; | ||
private final CoreConfiguration config; | ||
|
||
public AcraJobCreator(CoreConfiguration config) { | ||
this.config = config; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Job create(@NonNull String tag) { | ||
switch (tag) { | ||
case REPORT_TAG: | ||
return 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; | ||
} | ||
}; | ||
case RESTART_TAG: | ||
return new Job() { | ||
@NonNull | ||
@Override | ||
protected Result onRunJob(@NonNull Params params) { | ||
String className = params.getExtras().getString(RestartingAdministrator.EXTRA_LAST_ACTIVITY, null); | ||
if (className != null) { | ||
try { | ||
//noinspection unchecked | ||
Class<? extends Activity> activityClass = (Class<? extends Activity>) Class.forName(className); | ||
final Intent intent = new Intent(getContext(), activityClass); | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
getContext().startActivity(intent); | ||
} catch (ClassNotFoundException e) { | ||
ACRA.log.w(ACRA.LOG_TAG, "Unable to find activity class" + className); | ||
} | ||
} | ||
return Result.SUCCESS; | ||
} | ||
}; | ||
default: | ||
return null; | ||
} | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
acra-advanced-scheduler/src/main/java/org/acra/scheduler/RestartingAdministrator.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,60 @@ | ||
/* | ||
* 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.JobRequest; | ||
import com.evernote.android.job.util.support.PersistableBundleCompat; | ||
import com.google.auto.service.AutoService; | ||
import org.acra.builder.LastActivityManager; | ||
import org.acra.config.ConfigUtils; | ||
import org.acra.config.CoreConfiguration; | ||
import org.acra.config.ReportingAdministrator; | ||
import org.acra.config.SchedulerConfiguration; | ||
import org.acra.plugins.ConfigBasedAllowsDisablePlugin; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author F43nd1r | ||
* @since 07.05.18 | ||
*/ | ||
@AutoService(ReportingAdministrator.class) | ||
public class RestartingAdministrator extends ConfigBasedAllowsDisablePlugin implements ReportingAdministrator { | ||
public static final String EXTRA_LAST_ACTIVITY = "lastActivity"; | ||
|
||
public RestartingAdministrator() { | ||
super(SchedulerConfiguration.class); | ||
} | ||
|
||
@Override | ||
public boolean shouldFinishActivity(@NonNull Context context, @NonNull CoreConfiguration config, LastActivityManager lastActivityManager) { | ||
if (ConfigUtils.getPluginConfiguration(config, SchedulerConfiguration.class).restartAfterCrash() && lastActivityManager.getLastActivity() != null) { | ||
PersistableBundleCompat extras = new PersistableBundleCompat(); | ||
extras.putString(EXTRA_LAST_ACTIVITY, lastActivityManager.getLastActivity().getClass().getName()); | ||
new JobRequest.Builder(AcraJobCreator.RESTART_TAG) | ||
.setExact(TimeUnit.SECONDS.toMillis(1)) | ||
//.setExecutionWindow(TimeUnit.SECONDS.toMillis(10), TimeUnit.MINUTES.toMillis(1)) | ||
.setExtras(extras) | ||
.setUpdateCurrent(true) | ||
.build() | ||
.schedule(); | ||
} | ||
return true; | ||
} | ||
} |
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