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.spe; 18 19 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_BACKGROUND_JOBS_EXECUTION_REPORTED; 20 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_BACKGROUND_JOBS_EXECUTION_REPORTED__MODULE_NAME__MODULE_NAME_ADSERVICES; 21 import static com.android.adservices.service.stats.AdServicesStatsLog.BACKGROUND_JOB_SCHEDULING_REPORTED; 22 23 import com.android.adservices.service.stats.AdServicesStatsLog; 24 import com.android.adservices.service.stats.StatsdAdServicesLogger; 25 import com.android.adservices.shared.spe.logging.ExecutionReportedStats; 26 import com.android.adservices.shared.spe.logging.SchedulingReportedStats; 27 import com.android.adservices.shared.spe.logging.StatsdJobServiceLogger; 28 import com.android.internal.annotations.VisibleForTesting; 29 30 /** The AdServices' implementation of {@link StatsdAdServicesLogger}. */ 31 public final class AdServicesStatsdJobServiceLogger implements StatsdJobServiceLogger { 32 // Shorten the length of a single line. 33 @VisibleForTesting 34 static final int MODULE_NAME_AD_SERVICES = 35 AD_SERVICES_BACKGROUND_JOBS_EXECUTION_REPORTED__MODULE_NAME__MODULE_NAME_ADSERVICES; 36 37 @Override logExecutionReportedStats(ExecutionReportedStats stats)38 public void logExecutionReportedStats(ExecutionReportedStats stats) { 39 AdServicesStatsLog.write( 40 AD_SERVICES_BACKGROUND_JOBS_EXECUTION_REPORTED, 41 stats.getJobId(), 42 stats.getExecutionLatencyMs(), 43 stats.getExecutionPeriodMinute(), 44 stats.getExecutionResultCode(), 45 stats.getStopReason(), 46 MODULE_NAME_AD_SERVICES); 47 } 48 49 @Override logSchedulingReportedStats(SchedulingReportedStats stats)50 public void logSchedulingReportedStats(SchedulingReportedStats stats) { 51 AdServicesStatsLog.write( 52 BACKGROUND_JOB_SCHEDULING_REPORTED, 53 stats.getJobId(), 54 stats.getResultCode(), 55 stats.getSchedulerType(), 56 MODULE_NAME_AD_SERVICES); 57 } 58 } 59