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.signals; 18 19 import android.annotation.NonNull; 20 21 import com.android.adservices.LoggerFactory; 22 import com.android.adservices.service.adselection.AdIdFetcher; 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.Objects; 29 import java.util.concurrent.ExecutorService; 30 31 /** Class to generate egress configuration for signals */ 32 public interface EgressConfigurationGenerator { 33 34 /** 35 * @param packageName the package name of the caller. 36 * @param callingUid the calling uid of the caller. 37 * @return a Future of boolena value to determine if unlimited egress is enabled. 38 */ isUnlimitedEgressEnabledForAuction( @onNull String packageName, int callingUid)39 ListenableFuture<Boolean> isUnlimitedEgressEnabledForAuction( 40 @NonNull String packageName, int callingUid); 41 42 /** 43 * @param enablePasUnlimitedEgress boolean to indicate if the feature is enabled. 44 * @param adIdFetcher {@link com.android.adservices.service.adselection.AdIdFetcher} 45 * @param auctionServerAdIdFetchTimeoutMs the timeout for AdId Fetcher call to 46 * isUnlimitedEgressDataEnabled 47 * @param lightweightExecutorService Lightweight Executor Service. 48 * @return a new Instance of {@link EgressConfigurationGenerator} 49 */ createInstance( boolean enablePasUnlimitedEgress, @NonNull AdIdFetcher adIdFetcher, long auctionServerAdIdFetchTimeoutMs, @NonNull ExecutorService lightweightExecutorService)50 static EgressConfigurationGenerator createInstance( 51 boolean enablePasUnlimitedEgress, 52 @NonNull AdIdFetcher adIdFetcher, 53 long auctionServerAdIdFetchTimeoutMs, 54 @NonNull ExecutorService lightweightExecutorService) { 55 Objects.requireNonNull(adIdFetcher, "AdIdFetcher cannot be null"); 56 Objects.requireNonNull( 57 lightweightExecutorService, "Lightweight ExecutorService cannot be null"); 58 59 if (enablePasUnlimitedEgress) { 60 return (packageName, callingUid) -> 61 FluentFuture.from( 62 adIdFetcher.isLimitedAdTrackingEnabled( 63 packageName, 64 callingUid, 65 auctionServerAdIdFetchTimeoutMs)) 66 .transform( 67 isLatEnabled -> { 68 boolean isUnlimitedEgressDataEnabled = !isLatEnabled; 69 LoggerFactory.getFledgeLogger() 70 .v( 71 "Returning isUnlimitedEgressEnabled as: %b", 72 isUnlimitedEgressDataEnabled); 73 return isUnlimitedEgressDataEnabled; 74 }, 75 lightweightExecutorService); 76 } else { 77 return (packageName, callingUid) -> { 78 LoggerFactory.getFledgeLogger() 79 .v( 80 "mEnablePasUnlimitedEgress is set to false. Returning" 81 + " isUnlimitedEgressEnabledForAuction as false"); 82 return Futures.immediateFuture(false); 83 }; 84 } 85 } 86 } 87