Merge changes Ia9bb1597,I4f912afb
* changes:
Compos test compilation is only for dogfooders and is critical
Revert "Remove the daily job"
diff --git a/compos/composd/src/service.rs b/compos/composd/src/service.rs
index 49cfd3a..27c31e3 100644
--- a/compos/composd/src/service.rs
+++ b/compos/composd/src/service.rs
@@ -67,7 +67,10 @@
ApexSource::PreferStaged => true,
_ => unreachable!("Invalid ApexSource {:?}", apex_source),
};
- to_binder_result(self.do_start_test_compile(prefer_staged, callback))
+ // b/250929504 failure here intentionally crashes composd to trigger a bugreport
+ Ok(self
+ .do_start_test_compile(prefer_staged, callback)
+ .expect("Failed to start the test compile"))
}
}
diff --git a/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java b/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
index 479ae7f..be56430 100644
--- a/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
+++ b/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
@@ -23,6 +23,7 @@
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.content.ComponentName;
+import android.os.Build;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -44,10 +45,28 @@
*/
public class IsolatedCompilationJobService extends JobService {
private static final String TAG = IsolatedCompilationJobService.class.getName();
+ private static final int DAILY_JOB_ID = 5132250;
private static final int STAGED_APEX_JOB_ID = 5132251;
private final AtomicReference<CompilationJob> mCurrentJob = new AtomicReference<>();
+ static void scheduleDailyJob(JobScheduler scheduler) {
+ // This daily job is only for dogfooders (userdebug/eng)
+ if (Build.IS_USER) return;
+
+ ComponentName serviceName =
+ new ComponentName("android", IsolatedCompilationJobService.class.getName());
+
+ int result = scheduler.schedule(new JobInfo.Builder(DAILY_JOB_ID, serviceName)
+ .setRequiresDeviceIdle(true)
+ .setRequiresCharging(true)
+ .setPeriodic(TimeUnit.DAYS.toMillis(1))
+ .build());
+ if (result != JobScheduler.RESULT_SUCCESS) {
+ Log.e(TAG, "Failed to schedule daily job");
+ }
+ }
+
static void scheduleStagedApexJob(JobScheduler scheduler) {
ComponentName serviceName =
new ComponentName("android", IsolatedCompilationJobService.class.getName());
@@ -68,6 +87,7 @@
IsolatedCompilationMetrics.SCHEDULING_FAILURE);
Log.e(TAG, "Failed to schedule staged APEX job");
}
+
}
static boolean isStagedApexJobScheduled(JobScheduler scheduler) {
@@ -76,7 +96,9 @@
@Override
public boolean onStartJob(JobParameters params) {
- Log.i(TAG, "Starting job");
+ int jobId = params.getJobId();
+
+ Log.i(TAG, "Starting job " + jobId);
// This function (and onStopJob) are only ever called on the main thread, so we don't have
// to worry about two starts at once, or start and stop happening at once. But onCompletion
@@ -90,6 +112,9 @@
}
IsolatedCompilationMetrics metrics = new IsolatedCompilationMetrics();
+ if (jobId != STAGED_APEX_JOB_ID) {
+ metrics.disable();
+ }
CompilationJob newJob = new CompilationJob(IsolatedCompilationJobService.this::onCompletion,
params, metrics);
@@ -102,7 +127,7 @@
@Override
public void run() {
try {
- newJob.start();
+ newJob.start(jobId);
} catch (RuntimeException e) {
Log.e(TAG, "Starting CompilationJob failed", e);
metrics.onCompilationEnded(IsolatedCompilationMetrics.RESULT_FAILED_TO_START);
@@ -159,7 +184,7 @@
mMetrics = requireNonNull(metrics);
}
- void start() {
+ void start(int jobId) {
IBinder binder = ServiceManager.waitForService("android.system.composd");
IIsolatedCompilationService composd =
IIsolatedCompilationService.Stub.asInterface(binder);
@@ -169,7 +194,13 @@
}
try {
- ICompilationTask composTask = composd.startStagedApexCompile(this);
+ ICompilationTask composTask;
+ if (jobId == DAILY_JOB_ID) {
+ composTask = composd.startTestCompile(
+ IIsolatedCompilationService.ApexSource.NoStaged, this);
+ } else {
+ composTask = composd.startStagedApexCompile(this);
+ }
mMetrics.onCompilationStarted();
mTask.set(composTask);
composTask.asBinder().linkToDeath(this, 0);
@@ -191,24 +222,16 @@
private void cancelTask() {
ICompilationTask task = mTask.getAndSet(null);
- if (task == null) {
- return;
- }
-
- Log.i(TAG, "Cancelling task");
- try {
- task.cancel();
- } catch (RuntimeException | RemoteException e) {
- // If canceling failed we'll assume it means that the task has already failed;
- // there's nothing else we can do anyway.
- Log.w(TAG, "Failed to cancel CompilationTask", e);
- }
-
- mMetrics.onCompilationJobCanceled(mParams.getStopReason());
- try {
- task.asBinder().unlinkToDeath(this, 0);
- } catch (NoSuchElementException e) {
- // Harmless
+ if (task != null) {
+ Log.i(TAG, "Cancelling task");
+ try {
+ task.cancel();
+ mMetrics.onCompilationJobCanceled(mParams.getStopReason());
+ } catch (RuntimeException | RemoteException e) {
+ // If canceling failed we'll assume it means that the task has already failed;
+ // there's nothing else we can do anyway.
+ Log.w(TAG, "Failed to cancel CompilationTask", e);
+ }
}
}
diff --git a/compos/service/java/com/android/server/compos/IsolatedCompilationMetrics.java b/compos/service/java/com/android/server/compos/IsolatedCompilationMetrics.java
index e333198..df590f3 100644
--- a/compos/service/java/com/android/server/compos/IsolatedCompilationMetrics.java
+++ b/compos/service/java/com/android/server/compos/IsolatedCompilationMetrics.java
@@ -75,14 +75,21 @@
ArtStatsLog.ISOLATED_COMPILATION_SCHEDULED__SCHEDULING_RESULT__SCHEDULING_SUCCESS;
private long mCompilationStartTimeMs = 0;
+ private boolean mEnabled = true; // TODO(b/205296305) Remove this
public static void onCompilationScheduled(@ScheduleJobResult int result) {
ArtStatsLog.write(ArtStatsLog.ISOLATED_COMPILATION_SCHEDULED, result);
Log.i(TAG, "ISOLATED_COMPILATION_SCHEDULED: " + result);
}
+ public void disable() {
+ mEnabled = false;
+ }
+
public void onCompilationStarted() {
- mCompilationStartTimeMs = SystemClock.elapsedRealtime();
+ if (mEnabled) {
+ mCompilationStartTimeMs = SystemClock.elapsedRealtime();
+ }
}
public void onCompilationJobCanceled(@JobParameters.StopReason int jobStopReason) {
@@ -95,6 +102,9 @@
private void statsLogPostCompilation(@CompilationResult int result,
@JobParameters.StopReason int jobStopReason) {
+ if (!mEnabled) {
+ return;
+ }
long compilationTime = mCompilationStartTimeMs == 0 ? -1
: SystemClock.elapsedRealtime() - mCompilationStartTimeMs;
diff --git a/compos/service/java/com/android/server/compos/IsolatedCompilationService.java b/compos/service/java/com/android/server/compos/IsolatedCompilationService.java
index b2fcbe0..11e3743 100644
--- a/compos/service/java/com/android/server/compos/IsolatedCompilationService.java
+++ b/compos/service/java/com/android/server/compos/IsolatedCompilationService.java
@@ -67,6 +67,7 @@
return;
}
+ IsolatedCompilationJobService.scheduleDailyJob(scheduler);
StagedApexObserver.registerForStagedApexUpdates(scheduler);
}