Remove the daily job
This was only intended for testing, and we're passed that stage
now. We now only run compilation after an APEX is staged.
Also make a small fix so cancel also calls unlinkToDeath.
Bug: 220146954
Bug: 205296305
Test: Presubmit
Test: cmd jobscheduler get-job-state android 5132250 -> not found
Test: Stage apex, run the job, let it succeed, check logs
Test: Stage apex, run the job, cancel it, check logs
Change-Id: I54e44abaefe195e947c7965cee8c37c0b3680a1a
diff --git a/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java b/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
index f77406d..cf852e3 100644
--- a/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
+++ b/compos/service/java/com/android/server/compos/IsolatedCompilationJobService.java
@@ -44,26 +44,10 @@
*/
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) {
- // TODO(b/205296305) Remove this
- 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());
@@ -84,7 +68,6 @@
IsolatedCompilationMetrics.SCHEDULING_FAILURE);
Log.e(TAG, "Failed to schedule staged APEX job");
}
-
}
static boolean isStagedApexJobScheduled(JobScheduler scheduler) {
@@ -93,9 +76,7 @@
@Override
public boolean onStartJob(JobParameters params) {
- int jobId = params.getJobId();
-
- Log.i(TAG, "Starting job " + jobId);
+ Log.i(TAG, "Starting job");
// 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
@@ -109,9 +90,6 @@
}
IsolatedCompilationMetrics metrics = new IsolatedCompilationMetrics();
- if (jobId != STAGED_APEX_JOB_ID) {
- metrics.disable();
- }
CompilationJob newJob = new CompilationJob(IsolatedCompilationJobService.this::onCompletion,
params, metrics);
@@ -124,7 +102,7 @@
@Override
public void run() {
try {
- newJob.start(jobId);
+ newJob.start();
} catch (RuntimeException e) {
Log.e(TAG, "Starting CompilationJob failed", e);
metrics.onCompilationEnded(IsolatedCompilationMetrics.RESULT_FAILED_TO_START);
@@ -181,7 +159,7 @@
mMetrics = requireNonNull(metrics);
}
- void start(int jobId) {
+ void start() {
IBinder binder = ServiceManager.waitForService("android.system.composd");
IIsolatedCompilationService composd =
IIsolatedCompilationService.Stub.asInterface(binder);
@@ -191,13 +169,7 @@
}
try {
- ICompilationTask composTask;
- if (jobId == DAILY_JOB_ID) {
- composTask = composd.startTestCompile(
- IIsolatedCompilationService.ApexSource.NoStaged, this);
- } else {
- composTask = composd.startStagedApexCompile(this);
- }
+ ICompilationTask composTask = composd.startStagedApexCompile(this);
mMetrics.onCompilationStarted();
mTask.set(composTask);
composTask.asBinder().linkToDeath(this, 0);
@@ -219,16 +191,24 @@
private void cancelTask() {
ICompilationTask task = mTask.getAndSet(null);
- if (task != null) {
- Log.i(TAG, "Cancelling task");
- try {
- task.cancel();
- mMetrics.onCompilationEnded(IsolatedCompilationMetrics.RESULT_JOB_CANCELED);
- } 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);
- }
+ 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.onCompilationEnded(IsolatedCompilationMetrics.RESULT_JOB_CANCELED);
+ try {
+ task.asBinder().unlinkToDeath(this, 0);
+ } catch (NoSuchElementException e) {
+ // Harmless
}
}
diff --git a/compos/service/java/com/android/server/compos/IsolatedCompilationMetrics.java b/compos/service/java/com/android/server/compos/IsolatedCompilationMetrics.java
index a8fc39d..a35472b 100644
--- a/compos/service/java/com/android/server/compos/IsolatedCompilationMetrics.java
+++ b/compos/service/java/com/android/server/compos/IsolatedCompilationMetrics.java
@@ -53,7 +53,6 @@
public static final int SCHEDULING_FAILURE = 1;
private long mCompilationStartTimeMs = 0;
- private boolean mEnabled = true; // TODO(b/205296305) Remove this
public static void onCompilationScheduled(@ScheduleJobResult int result) {
// TODO(b/218525257): write to ArtStatsLog instead of logcat
@@ -61,21 +60,11 @@
Log.i(TAG, "ISOLATED_COMPILATION_SCHEDULED: " + result);
}
- public void disable() {
- mEnabled = false;
- }
-
public void onCompilationStarted() {
- if (mEnabled) {
- mCompilationStartTimeMs = SystemClock.elapsedRealtime();
- }
+ mCompilationStartTimeMs = SystemClock.elapsedRealtime();
}
public void onCompilationEnded(@CompilationResult int result) {
- if (!mEnabled) {
- return;
- }
-
long compilationTime = mCompilationStartTimeMs == 0 ? -1
: SystemClock.elapsedRealtime() - mCompilationStartTimeMs;
mCompilationStartTimeMs = 0;
diff --git a/compos/service/java/com/android/server/compos/IsolatedCompilationService.java b/compos/service/java/com/android/server/compos/IsolatedCompilationService.java
index 11e3743..b2fcbe0 100644
--- a/compos/service/java/com/android/server/compos/IsolatedCompilationService.java
+++ b/compos/service/java/com/android/server/compos/IsolatedCompilationService.java
@@ -67,7 +67,6 @@
return;
}
- IsolatedCompilationJobService.scheduleDailyJob(scheduler);
StagedApexObserver.registerForStagedApexUpdates(scheduler);
}