1 /* 2 * Copyright (C) 2023 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.adselection; 18 19 import android.annotation.NonNull; 20 21 import com.android.adservices.LoggerFactory; 22 import com.android.adservices.service.Flags; 23 24 import com.google.common.util.concurrent.FluentFuture; 25 import com.google.common.util.concurrent.Futures; 26 import com.google.common.util.concurrent.ListenableFuture; 27 28 import java.util.concurrent.ExecutorService; 29 30 public class AuctionServerDebugReporting { 31 32 private static final LoggerFactory.Logger sLogger = LoggerFactory.getFledgeLogger(); 33 34 private final boolean mIsEnabled; 35 AuctionServerDebugReporting(boolean isEnabled)36 private AuctionServerDebugReporting(boolean isEnabled) { 37 this.mIsEnabled = isEnabled; 38 } 39 40 /** 41 * @return an instance of auction server debug reporting after checking for is limited ad 42 * tracking is enabled or not. 43 */ createInstance( @onNull Flags flags, @NonNull AdIdFetcher adIdFetcher, @NonNull String packageName, int callingUid, @NonNull ExecutorService lightweightExecutorService)44 public static ListenableFuture<AuctionServerDebugReporting> createInstance( 45 @NonNull Flags flags, 46 @NonNull AdIdFetcher adIdFetcher, 47 @NonNull String packageName, 48 int callingUid, 49 @NonNull ExecutorService lightweightExecutorService) { 50 if (!getEnablementStatus(flags)) { 51 return Futures.immediateFuture(createForDebugReportingDisabled()); 52 } 53 long auctionServerAdIdFetchTimeoutMs = flags.getFledgeAuctionServerAdIdFetcherTimeoutMs(); 54 return FluentFuture.from( 55 adIdFetcher.isLimitedAdTrackingEnabled( 56 packageName, callingUid, auctionServerAdIdFetchTimeoutMs)) 57 .transform( 58 isLatEnabled -> new AuctionServerDebugReporting(!isLatEnabled), 59 lightweightExecutorService); 60 } 61 62 /** 63 * @return an instance of auction server debug reporting as disabled 64 */ createForDebugReportingDisabled()65 public static AuctionServerDebugReporting createForDebugReportingDisabled() { 66 return new AuctionServerDebugReporting(false); 67 } 68 69 /** 70 * @return returns status of auction server debug reporting 71 */ isEnabled()72 public boolean isEnabled() { 73 return mIsEnabled; 74 } 75 getEnablementStatus(Flags flags)76 private static boolean getEnablementStatus(Flags flags) { 77 if (flags.getAdIdKillSwitch()) { 78 sLogger.v("AdIdService kill switch is enabled, disabling event level debug reporting"); 79 return false; 80 } 81 return flags.getFledgeAuctionServerEnableDebugReporting(); 82 } 83 } 84