1 /* 2 * Copyright (C) 2024 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.adservices.shared.spe.framework; 18 19 import com.android.adservices.shared.common.flags.ModuleSharedFlags; 20 import com.android.adservices.shared.errorlogging.AdServicesErrorLogger; 21 import com.android.adservices.shared.proto.ModuleJobPolicy; 22 import com.android.adservices.shared.spe.logging.JobSchedulingLogger; 23 import com.android.adservices.shared.spe.logging.JobServiceLogger; 24 import com.android.adservices.shared.spe.scheduling.PolicyJobScheduler; 25 26 import java.util.Map; 27 import java.util.concurrent.Executor; 28 29 /** 30 * The configuration a module should set in order to use the SPE (Scheduling Policy Engine) 31 * framework, including {@link AbstractJobService} and {@link PolicyJobScheduler}. {@code 32 * adservices/service-core/java/com/android/adservices/spe/AdServicesJobServiceConfig.java} can be 33 * used as an example. 34 */ 35 public interface JobServiceFactory { 36 /** 37 * Creates a {@link JobWorker} instance given a unique job ID. This method helps to invoke 38 * associated methods belonging to a {@link JobWorker} when the Platform scheduler invokes it 39 * during the {@link android.app.job.JobService}'s Lifecycle. 40 * 41 * @param jobId the unique job ID in a module. 42 * @return the instance of the job associated with the given job ID. 43 */ getJobWorkerInstance(int jobId)44 JobWorker getJobWorkerInstance(int jobId); 45 46 /** 47 * Gets a mapping between the job ID and the job name for a job. This method helps to provide 48 * informative logging. 49 * 50 * @return the mapping of job ID and job name. 51 */ getJobIdToNameMap()52 Map<Integer, String> getJobIdToNameMap(); 53 54 /** Gets an instance of {@link JobServiceLogger}. */ getJobServiceLogger()55 JobServiceLogger getJobServiceLogger(); 56 57 /** Gets an instance of {@link JobSchedulingLogger}. */ getJobSchedulingLogger()58 JobSchedulingLogger getJobSchedulingLogger(); 59 60 /** Gets an instance of {@link AdServicesErrorLogger}. */ getErrorLogger()61 AdServicesErrorLogger getErrorLogger(); 62 63 /** 64 * Gets the executor used for framework-level tasks. For example, logging, cancelling jobs in 65 * the background, scheduling jobs in the background, etc. 66 * 67 * <p>Note it recommends to use background executor because the task is not light and doesn't 68 * require Internet. 69 */ getBackgroundExecutor()70 Executor getBackgroundExecutor(); 71 72 /** Gets the {@link ModuleJobPolicy}. It stores the policy info parsed from the server. */ getModuleJobPolicy()73 ModuleJobPolicy getModuleJobPolicy(); 74 75 /** Gets the flags configured by a module to pass into SPE. */ getFlags()76 ModuleSharedFlags getFlags(); 77 } 78