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.statsd.joblogging; 18 19 import static com.android.ondevicepersonalization.services.OnDevicePersonalizationConfig.JOB_ID_TO_NAME_MAP; 20 21 import android.content.Context; 22 23 import com.android.adservices.shared.common.flags.ModuleSharedFlags; 24 import com.android.adservices.shared.errorlogging.AdServicesErrorLogger; 25 import com.android.adservices.shared.spe.logging.JobServiceLogger; 26 import com.android.adservices.shared.spe.logging.StatsdJobServiceLogger; 27 import com.android.adservices.shared.util.Clock; 28 import com.android.internal.annotations.GuardedBy; 29 import com.android.ondevicepersonalization.services.FlagsFactory; 30 import com.android.ondevicepersonalization.services.OnDevicePersonalizationExecutors; 31 import com.android.ondevicepersonalization.services.statsd.errorlogging.ClientErrorLogger; 32 33 import java.util.Map; 34 import java.util.concurrent.Executor; 35 36 /** A background job logger to log ODP background job stats. */ 37 public final class OdpJobServiceLogger extends JobServiceLogger { 38 @GuardedBy("SINGLETON_LOCK") 39 private static volatile OdpJobServiceLogger sSingleton; 40 41 private static final Object SINGLETON_LOCK = new Object(); 42 43 /** Create an instance of {@link JobServiceLogger}. */ OdpJobServiceLogger( Context context, Clock clock, StatsdJobServiceLogger statsdLogger, AdServicesErrorLogger errorLogger, Executor executor, Map<Integer, String> jobIdToNameMap, ModuleSharedFlags flags)44 public OdpJobServiceLogger( 45 Context context, 46 Clock clock, 47 StatsdJobServiceLogger statsdLogger, 48 AdServicesErrorLogger errorLogger, 49 Executor executor, 50 Map<Integer, String> jobIdToNameMap, 51 ModuleSharedFlags flags) { 52 super(context, clock, statsdLogger, errorLogger, executor, jobIdToNameMap, flags); 53 } 54 55 /** Get a singleton instance of {@link JobServiceLogger} to be used. */ getInstance(Context context)56 public static OdpJobServiceLogger getInstance(Context context) { 57 synchronized (SINGLETON_LOCK) { 58 if (sSingleton == null) { 59 sSingleton = 60 new OdpJobServiceLogger( 61 context, 62 Clock.getInstance(), 63 new OdpStatsdJobServiceLogger(), 64 ClientErrorLogger.getInstance(), 65 OnDevicePersonalizationExecutors.getBackgroundExecutor(), 66 JOB_ID_TO_NAME_MAP, 67 FlagsFactory.getFlags()); 68 } 69 70 return sSingleton; 71 } 72 } 73 } 74