Don't crash system server on start job failure
It helps to catch the exception on the right thread.
Bug: 208344101
Test: Inject failure, system server no longer crashes
Change-Id: Ic0bb080d678f5922825441a62a6d03ec5b938d86
diff --git a/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java b/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
index 2aacc2d..da399cc 100644
--- a/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
+++ b/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
@@ -68,20 +68,21 @@
CompilationJob newJob = new CompilationJob(callback);
mCurrentJob.set(newJob);
- try {
- // This can take some time - we need to start up a VM - so we do it on a separate
- // thread. This thread exits as soon as the compilation Ttsk has been started (or
- // there's a failure), and then compilation continues in composd and the VM.
- new Thread("IsolatedCompilationJob_starter") {
- @Override
- public void run() {
+ // This can take some time - we need to start up a VM - so we do it on a separate
+ // thread. This thread exits as soon as the compilation Task has been started (or
+ // there's a failure), and then compilation continues in composd and the VM.
+ new Thread("IsolatedCompilationJob_starter") {
+ @Override
+ public void run() {
+ try {
newJob.start();
+ } catch (RuntimeException e) {
+ Log.e(TAG, "Starting CompilationJob failed", e);
+ newJob.stop(); // Just in case it managed to start before failure
+ jobFinished(params, /*wantReschedule=*/ false);
}
- }.start();
- } catch (RuntimeException e) {
- Log.e(TAG, "Starting CompilationJob failed", e);
- return false; // We're finished
- }
+ }
+ }.start();
return true; // Job is running in the background
}