• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.art;
18 
19 import android.annotation.NonNull;
20 import android.app.job.JobParameters;
21 import android.app.job.JobService;
22 import android.os.Build;
23 
24 import androidx.annotation.RequiresApi;
25 
26 import com.android.modules.utils.build.SdkLevel;
27 import com.android.server.LocalManagerRegistry;
28 import com.android.server.art.model.ArtServiceJobInterface;
29 
30 /**
31  * Entry point for the callback from the job scheduler. This class is instantiated by the system
32  * automatically.
33  *
34  * This class is for all ART Service jobs, not only the background dexopt job but also the
35  * Pre-reboot Dexopt job. We cannot change its name because its hardcoded on the platform side.
36  *
37  * @hide
38  */
39 @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
40 public class BackgroundDexoptJobService extends JobService {
41     @Override
onStartJob(@onNull JobParameters params)42     public boolean onStartJob(@NonNull JobParameters params) {
43         return getJob(params.getJobId()).onStartJob(this, params);
44     }
45 
46     @Override
onStopJob(@onNull JobParameters params)47     public boolean onStopJob(@NonNull JobParameters params) {
48         return getJob(params.getJobId()).onStopJob(params);
49     }
50 
51     @NonNull
getJob(int jobId)52     static ArtServiceJobInterface getJob(int jobId) {
53         if (jobId == BackgroundDexoptJob.JOB_ID) {
54             return LocalManagerRegistry.getManager(ArtManagerLocal.class).getBackgroundDexoptJob();
55         } else if (jobId == PreRebootDexoptJob.JOB_ID && SdkLevel.isAtLeastV()) {
56             return LocalManagerRegistry.getManager(ArtManagerLocal.class).getPreRebootDexoptJob();
57         }
58         throw new IllegalArgumentException("Unknown job ID " + jobId);
59     }
60 }
61