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.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_ON_DEVICE_PERSONALIZATION;
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.shared.spe.logging.ExecutionReportedStats;
25 import com.android.adservices.shared.spe.logging.SchedulingReportedStats;
26 import com.android.adservices.shared.spe.logging.StatsdJobServiceLogger;
27 
28 /** ODP implementation of {@link StatsdJobServicesLogger}. */
29 public final class OdpStatsdJobServiceLogger implements StatsdJobServiceLogger {
30 
31     @Override
logExecutionReportedStats(ExecutionReportedStats stats)32     public void logExecutionReportedStats(ExecutionReportedStats stats) {
33         AdServicesStatsLog.write(
34                 AD_SERVICES_BACKGROUND_JOBS_EXECUTION_REPORTED,
35                 stats.getJobId(),
36                 stats.getExecutionLatencyMs(),
37                 stats.getExecutionPeriodMinute(),
38                 stats.getExecutionResultCode(),
39                 stats.getStopReason(),
40                 AD_SERVICES_BACKGROUND_JOBS_EXECUTION_REPORTED__MODULE_NAME__MODULE_NAME_ON_DEVICE_PERSONALIZATION);
41     }
42 
43     @Override
logSchedulingReportedStats(SchedulingReportedStats stats)44     public void logSchedulingReportedStats(SchedulingReportedStats stats) {
45         AdServicesStatsLog.write(
46                 BACKGROUND_JOB_SCHEDULING_REPORTED,
47                 stats.getJobId(),
48                 stats.getResultCode(),
49                 stats.getSchedulerType(),
50                 AD_SERVICES_BACKGROUND_JOBS_EXECUTION_REPORTED__MODULE_NAME__MODULE_NAME_ON_DEVICE_PERSONALIZATION);
51     }
52 }
53