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.ondevicepersonalization.services.sharedlibrary.spe; 18 19 import android.content.Context; 20 21 import com.android.adservices.shared.spe.scheduling.JobSpec; 22 import com.android.adservices.shared.spe.scheduling.PolicyJobScheduler; 23 import com.android.internal.annotations.GuardedBy; 24 25 public final class OdpJobScheduler extends PolicyJobScheduler<OdpJobService> { 26 private static final Object SINGLETON_LOCK = new Object(); 27 28 @GuardedBy("SINGLETON_LOCK") 29 private static volatile OdpJobScheduler sSingleton; 30 31 private final Context mContext; 32 OdpJobScheduler(Context context)33 private OdpJobScheduler(Context context) { 34 super(OdpJobServiceFactory.getInstance(context), OdpJobService.class); 35 mContext = context.getApplicationContext(); 36 } 37 38 /** Gets the singleton instance of {@link OdpJobScheduler}. */ getInstance(Context context)39 public static OdpJobScheduler getInstance(Context context) { 40 synchronized (SINGLETON_LOCK) { 41 if (sSingleton == null) { 42 sSingleton = new OdpJobScheduler(context); 43 } 44 45 return sSingleton; 46 } 47 } 48 49 /** 50 * An overloading method to {@link PolicyJobScheduler#schedule(Context, JobSpec)} with passing 51 * in ODP's app context. 52 * 53 * @param jobSpec a {@link JobSpec} that stores the specifications used to schedule a job. 54 */ schedule(Context context, JobSpec jobSpec)55 public void schedule(Context context, JobSpec jobSpec) { 56 super.schedule(mContext, jobSpec); 57 } 58 } 59