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 import com.android.adservices.shared.util.Clock; 24 25 import java.util.Objects; 26 27 public class SelectAdsFromOutcomesExecutionLoggerFactory { 28 private final Clock mClock; 29 30 private final AdServicesLogger mAdServicesLogger; 31 32 private final boolean mFledgeSelectAdsFromOutcomesMetricsEnabled; 33 SelectAdsFromOutcomesExecutionLoggerFactory( @onNull Clock clock, @NonNull AdServicesLogger adServicesLogger, @NonNull Flags flags)34 public SelectAdsFromOutcomesExecutionLoggerFactory( 35 @NonNull Clock clock, 36 @NonNull AdServicesLogger adServicesLogger, 37 @NonNull Flags flags) { 38 Objects.requireNonNull(clock); 39 Objects.requireNonNull(adServicesLogger); 40 Objects.requireNonNull(flags); 41 mFledgeSelectAdsFromOutcomesMetricsEnabled = 42 BinderFlagReader.readFlag(flags::getFledgeSelectAdsFromOutcomesApiMetricsEnabled); 43 mClock = clock; 44 mAdServicesLogger = adServicesLogger; 45 } 46 47 /** 48 * Gets the {@link SelectAdsFromOutcomesExecutionLogger} implementation to use, dependent on 49 * whether the Fledge Select Ads From Outcomes Metrics Enabled are enabled. 50 * 51 * @return an {@link SelectAdsFromOutcomesExecutionLoggerImpl} instance if the Fledge Select Ads 52 * From Outcomes metrics are enabled, or {@link 53 * SelectAdsFromOutcomesExecutionLoggerNoLoggingImpl} instance otherwise 54 */ getSelectAdsFromOutcomesExecutionLogger()55 public SelectAdsFromOutcomesExecutionLogger getSelectAdsFromOutcomesExecutionLogger() { 56 if (mFledgeSelectAdsFromOutcomesMetricsEnabled) { 57 return new SelectAdsFromOutcomesExecutionLoggerImpl(mClock, mAdServicesLogger); 58 } 59 return new SelectAdsFromOutcomesExecutionLoggerNoLoggingImpl(); 60 } 61 } 62