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.service.stats;
18 
19 import android.annotation.NonNull;
20 
21 import com.android.adservices.service.Flags;
22 import com.android.adservices.service.common.BinderFlagReader;
23 
24 import java.util.Objects;
25 
26 public class ReportImpressionExecutionLoggerFactory {
27     private final AdServicesLogger mAdServicesLogger;
28 
29     private final Flags mFlags;
30 
31     private final boolean mFledgeReportImpressionApiMetricsEnabled;
32 
ReportImpressionExecutionLoggerFactory( @onNull AdServicesLogger adServicesLogger, @NonNull Flags flags)33     public ReportImpressionExecutionLoggerFactory(
34             @NonNull AdServicesLogger adServicesLogger, @NonNull Flags flags) {
35         Objects.requireNonNull(adServicesLogger);
36         Objects.requireNonNull(flags);
37         mFledgeReportImpressionApiMetricsEnabled =
38                 BinderFlagReader.readFlag(flags::getFledgeReportImpressionApiMetricsEnabled);
39         mAdServicesLogger = adServicesLogger;
40         mFlags = flags;
41     }
42 
43     /**
44      * Gets the {@link ReportImpressionExecutionLogger} implementation to use, dependent on whether
45      * the Fledge Select Ads From Outcomes Metrics Enabled are enabled.
46      *
47      * @return an {@link ReportImpressionExecutionLoggerImpl} instance if the Fledge Select Ads From
48      *     Outcomes metrics are enabled, or {@link ReportImpressionExecutionLoggerNoLoggingImpl}
49      *     instance otherwise
50      */
getReportImpressionExecutionLogger()51     public ReportImpressionExecutionLogger getReportImpressionExecutionLogger() {
52         if (mFledgeReportImpressionApiMetricsEnabled) {
53             return new ReportImpressionExecutionLoggerImpl(mAdServicesLogger, mFlags);
54         }
55         return new ReportImpressionExecutionLoggerNoLoggingImpl();
56     }
57 }
58