1 /* 2 * Copyright (C) 2022 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 android.adservices.adselection; 18 19 import android.adservices.adselection.AdSelectionCallback; 20 import android.adservices.adselection.AdSelectionConfig; 21 import android.adservices.adselection.AdSelectionFromOutcomesConfig; 22 import android.adservices.adselection.AdSelectionFromOutcomesInput; 23 import android.adservices.adselection.AdSelectionInput; 24 import android.adservices.adselection.AdSelectionOutcome; 25 import android.adservices.adselection.AdSelectionOverrideCallback; 26 import android.adservices.adselection.PerBuyerDecisionLogic; 27 import android.adservices.adselection.GetAdSelectionDataCallback; 28 import android.adservices.adselection.GetAdSelectionDataInput; 29 import android.adservices.adselection.PersistAdSelectionResultCallback; 30 import android.adservices.adselection.PersistAdSelectionResultInput; 31 import android.adservices.adselection.RemoveAdCounterHistogramOverrideInput; 32 import android.adservices.adselection.ReportImpressionCallback; 33 import android.adservices.adselection.ReportImpressionInput; 34 import android.adservices.adselection.ReportInteractionCallback; 35 import android.adservices.adselection.ReportInteractionInput; 36 import android.adservices.adselection.SetAdCounterHistogramOverrideInput; 37 import android.adservices.adselection.SetAppInstallAdvertisersCallback; 38 import android.adservices.adselection.SetAppInstallAdvertisersInput; 39 import android.adservices.adselection.UpdateAdCounterHistogramCallback; 40 import android.adservices.adselection.UpdateAdCounterHistogramInput; 41 import android.adservices.common.AdSelectionSignals; 42 import android.adservices.common.CallerMetadata; 43 import android.net.Uri; 44 import java.util.List; 45 46 /** 47 * This is the Ad Selection Service, which defines the interface used for the Ad selection workflow 48 * to orchestrate the on-device execution of 49 * 1. Ad selection data collection. 50 * 2. Ad selection. 51 * 3. Impression reporting. 52 * 4. Interaction reporting. 53 * 5. Ad event counting. 54 * 55 * @hide 56 */ 57 interface AdSelectionService { 58 /** 59 * This method collects data from device for ad selection 60 * 61 * @hide 62 */ getAdSelectionData(in GetAdSelectionDataInput request, in CallerMetadata callerMetadata, in GetAdSelectionDataCallback callback)63 void getAdSelectionData(in GetAdSelectionDataInput request, in CallerMetadata callerMetadata, 64 in GetAdSelectionDataCallback callback); 65 66 /** 67 * This method persists the results from a finished ad selection on servers 68 * 69 * @hide 70 */ persistAdSelectionResult(in PersistAdSelectionResultInput request, in CallerMetadata callerMetadata, in PersistAdSelectionResultCallback callback)71 void persistAdSelectionResult(in PersistAdSelectionResultInput request, 72 in CallerMetadata callerMetadata, in PersistAdSelectionResultCallback callback); 73 74 /** 75 * This method orchestrates the buyer and seller side logic to pick the winning ad amongst all 76 * the on-device remarketing ad candidates and seller provided contextual ad candidates. It will 77 * execuate the ad tech-provided Javascript code based on the following sequence: 78 * 1. Buy-side bidding logic execution 79 * 2. Buy-side ad filtering and processing(i.e. brand safety check, frequency capping, generated 80 * bid validation etc.) 81 * 3. Sell-side decision logic execution to determine a winning ad based on bidding loigic 82 * outputs and business logic. 83 * 84 * An AdSelectionInput is a request object that contains a {@link AdSelectionConfig} 85 * and a String callerPackageName 86 * 87 * The {@link AdSelectionConfig} is provided by the SDK and contains the required information 88 * to execute the on-device ad selection and impression reporting. 89 * 90 * The (@link AdSelectionCallback} returns {@link AdSelectionResponse} if the asynchronous call 91 * succeeds. 92 * The (@link AdSelectionCallback} returns {@link FledgeErrorResponse} if the asynchronous call 93 * fails. 94 * If the ad selection is successful, the {@link AdSelectionResponse} contains 95 * {@link AdSelectionId} and {@link RenderUri} 96 * If the ad selection fails, the response contains only 97 * {@link FledgeErrorResponse#RESULT_INTERNAL_ERROR} if an internal server error is encountered, 98 * or {@link FledgeErrorResponse#RESULT_INVALID_ARGUMENT} if: 99 * 1. The supplied {@link AdSelectionConfig} is invalid 100 * 2. The {@link AdSelectionInput#getCallerPackageName} does not match the package name of the 101 * application calling this API 102 * 103 * Otherwise, this call fails to send the response to the callback and throws a RemoteException. 104 * 105 * @hide 106 */ selectAds(in AdSelectionInput request, in CallerMetadata callerMetadata, in AdSelectionCallback callback)107 void selectAds(in AdSelectionInput request, in CallerMetadata callerMetadata, 108 in AdSelectionCallback callback); 109 110 /** 111 * This method allows to select an ad from a list of ads that are winner outcomes of separate 112 * runAdSelection. This method will execute a given logic and signals on given list of ads and 113 * will return either one or none of the ads. 114 * 115 * {@code adOutcomes} is a list of {@link AdSelectionOutcome} where each element is a winner 116 * from a call to {@code runAdSelection} method. 117 * {@code selectionSignals} contains any signals ad-tech wish to use during the decision making. 118 * {@code selectionLogicUri} points to a decision logic for selection. There are two types; 119 * <lu> 120 * <li> 121 * An HTTPS url to download the java script logic from. 122 * </li> 123 * <li> 124 * A uri that points to the pre-built logics. 125 * </li> 126 * </lu> 127 * 128 * 129 * The (@link AdSelectionCallback} returns {@link AdSelectionResponse} if the asynchronous call 130 * succeeds. 131 * The (@link AdSelectionCallback} returns {@link FledgeErrorResponse} if the asynchronous call 132 * fails. 133 * 134 * If the outcome selection is successful, the {@link AdSelectionResponse} contains 135 * {@link AdSelectionId} and {@link RenderUri} 136 * If the ad selection fails, the response contains only 137 * {@link FledgeErrorResponse#RESULT_INTERNAL_ERROR} if an internal server error is encountered, 138 * or {@link FledgeErrorResponse#RESULT_INVALID_ARGUMENT} if: 139 * 1. The supplied list of {@link AdSelectionOutcomes} is invalid or 140 * 2. The supplied {@link SelectionLogicUri} is invalid. 141 * 142 * Otherwise, this call fails to send the response to the callback and throws a RemoteException. 143 * 144 * {@hide} 145 */ selectAdsFromOutcomes(in AdSelectionFromOutcomesInput inputParams, in CallerMetadata callerMetadata, in AdSelectionCallback callback)146 void selectAdsFromOutcomes(in AdSelectionFromOutcomesInput inputParams, 147 in CallerMetadata callerMetadata, in AdSelectionCallback callback); 148 149 /** 150 * Notifies PPAPI that there is a new impression to report for the 151 * ad selected by the ad-selection run identified by {@code adSelectionId}. 152 * There is no guarantee about when the event will be reported. The event 153 * reporting could be delayed and events could be batched. 154 * 155 * The call will fail with a status of 156 * {@link FledgeErrorResponse#STATUS_INVALID_ARGUMENT} if: 157 * 1. There is no ad selection matching the provided {@link 158 * ReportImpressionInput#getAdSelectionId()} 159 * 2. The supplied {@link ReportImpressionInput#getAdSelectionConfig()} is invalid 160 * 3. The {@link AdSelectionConfig#getCallerPackageName} does not match the package name of the 161 * application calling this API The call will fail with status 162 * {@link FledgeErrorResponse#STATUS_INTERNAL_ERROR} if an 163 * internal server error is encountered. 164 * 165 * The reporting guarantee is at-most-once, any error during the connection to 166 * the seller and/or buyer reporting URIs might be retried but we won't 167 * guarantee the completion. 168 * 169 * {@hide} 170 */ reportImpression(in ReportImpressionInput request, in ReportImpressionCallback callback)171 void reportImpression(in ReportImpressionInput request, in ReportImpressionCallback callback); 172 173 /** 174 * Notifies PPAPI that there is a new interaction to report for the 175 * ad selected by the ad-selection run identified by {@code adSelectionId}. 176 */ reportInteraction( in ReportInteractionInput inputParams, in ReportInteractionCallback callback)177 void reportInteraction( 178 in ReportInteractionInput inputParams, in ReportInteractionCallback callback); 179 180 /** 181 * Updates the counter histograms for the ad event counters associated with a FLEDGE-selected 182 * ad. 183 */ updateAdCounterHistogram(in UpdateAdCounterHistogramInput inputParams, in UpdateAdCounterHistogramCallback callback)184 void updateAdCounterHistogram(in UpdateAdCounterHistogramInput inputParams, 185 in UpdateAdCounterHistogramCallback callback); 186 187 /** 188 * This method is intended to be called before {@code runAdSelection} 189 * and {@code reportImpression} using the same 190 * {@link AdSelectionConfig} in order to configure 191 * PPAPI to avoid to fetch info from remote servers and use the 192 * data provided. 193 * 194 * The call will throw a SecurityException if the API hasn't been enabled 195 * by developer options or by an adb command or if the calling 196 * application manifest is not setting Android:debuggable to true. 197 */ overrideAdSelectionConfigRemoteInfo(in AdSelectionConfig adSelectionConfig, in String decisionLogicJS, in AdSelectionSignals trustedScoringSignals, in PerBuyerDecisionLogic perBuyerDecisionLogic, in AdSelectionOverrideCallback callback)198 void overrideAdSelectionConfigRemoteInfo(in AdSelectionConfig adSelectionConfig, 199 in String decisionLogicJS, in AdSelectionSignals trustedScoringSignals, 200 in PerBuyerDecisionLogic perBuyerDecisionLogic, in AdSelectionOverrideCallback callback); 201 /** 202 * Gives the provided list of adtechs permission do app install filtering based on the presence 203 * of the calling app. 204 * @hide 205 */ setAppInstallAdvertisers( in SetAppInstallAdvertisersInput request, in SetAppInstallAdvertisersCallback callback)206 void setAppInstallAdvertisers( 207 in SetAppInstallAdvertisersInput request, in SetAppInstallAdvertisersCallback callback); 208 209 /** 210 * Deletes any override created by calling 211 * {@code overrideAdSelectionConfigRemoteInfo} for the given 212 * AdSelectionConfig 213 * 214 * The call will throw a SecurityException if: 215 * the API hasn't been enabled by developer options or by an adb command 216 * or if the calling application manifest is not setting Android:debuggable to true. 217 */ removeAdSelectionConfigRemoteInfoOverride( in AdSelectionConfig adSelectionConfig, in AdSelectionOverrideCallback callback)218 void removeAdSelectionConfigRemoteInfoOverride( 219 in AdSelectionConfig adSelectionConfig, in AdSelectionOverrideCallback callback); 220 221 /** 222 * Deletes any override created by calling 223 * {@code overrideAdSelectionConfigRemoteInfo} from this application 224 * 225 * The call will throw a SecurityException if: 226 * the API hasn't been enabled by developer options or by an adb command 227 * or if the calling application manifest is not setting Android:debuggable to true. 228 */ resetAllAdSelectionConfigRemoteOverrides(in AdSelectionOverrideCallback callback)229 void resetAllAdSelectionConfigRemoteOverrides(in AdSelectionOverrideCallback callback); 230 231 /** 232 * This method is intended to be called before {@code selectAdsFromOutcomes} 233 * using the same {@link AdSelectionFromOutcomesConfig} in order to configure 234 * PPAPI to avoid to fetch info from remote servers and use the 235 * data provided. 236 * 237 * The call will throw a SecurityException if the API hasn't been enabled 238 * by developer options or by an adb command or if the calling 239 * application manifest is not setting Android:debuggable to true. 240 */ overrideAdSelectionFromOutcomesConfigRemoteInfo( in AdSelectionFromOutcomesConfig adSelectionFromOutcomesConfig, in String selectionLogicJs, in AdSelectionSignals selectionSignals, in AdSelectionOverrideCallback callback)241 void overrideAdSelectionFromOutcomesConfigRemoteInfo( 242 in AdSelectionFromOutcomesConfig adSelectionFromOutcomesConfig, 243 in String selectionLogicJs, in AdSelectionSignals selectionSignals, 244 in AdSelectionOverrideCallback callback); 245 246 /** 247 * Deletes any override created by calling 248 * {@code overrideAdSelectionFromOutcomesConfigRemoteInfo} for the given 249 * AdSelectionFromOutcomesConfig 250 * 251 * The call will throw a SecurityException if: 252 * the API hasn't been enabled by developer options or by an adb command 253 * or if the calling application manifest is not setting Android:debuggable to true. 254 */ removeAdSelectionFromOutcomesConfigRemoteInfoOverride( in AdSelectionFromOutcomesConfig adSelectionFromOutcomesConfig, in AdSelectionOverrideCallback callback)255 void removeAdSelectionFromOutcomesConfigRemoteInfoOverride( 256 in AdSelectionFromOutcomesConfig adSelectionFromOutcomesConfig, 257 in AdSelectionOverrideCallback callback); 258 259 /** 260 * Deletes any override created by calling 261 * {@code overrideAdSelectionFromOutcomesConfigRemoteInfo} from this application 262 * 263 * The call will throw a SecurityException if: 264 * the API hasn't been enabled by developer options or by an adb command 265 * or if the calling application manifest is not setting Android:debuggable to true. 266 */ resetAllAdSelectionFromOutcomesConfigRemoteOverrides( in AdSelectionOverrideCallback callback)267 void resetAllAdSelectionFromOutcomesConfigRemoteOverrides( 268 in AdSelectionOverrideCallback callback); 269 270 /** 271 * Manually overrides the histogram to be used in ad selection with the specified event 272 * histogram. 273 */ setAdCounterHistogramOverride(in SetAdCounterHistogramOverrideInput inputParams, in AdSelectionOverrideCallback callback)274 void setAdCounterHistogramOverride(in SetAdCounterHistogramOverrideInput inputParams, 275 in AdSelectionOverrideCallback callback); 276 277 /** 278 * Removes a previously set histogram override used in ad selection. 279 */ removeAdCounterHistogramOverride(in RemoveAdCounterHistogramOverrideInput inputParams, in AdSelectionOverrideCallback callback)280 void removeAdCounterHistogramOverride(in RemoveAdCounterHistogramOverrideInput inputParams, 281 in AdSelectionOverrideCallback callback); 282 283 /** 284 * Removes all previously set histogram overrides used in ad selection which were set by the 285 * caller application. 286 */ resetAllAdCounterHistogramOverrides(in AdSelectionOverrideCallback callback)287 void resetAllAdCounterHistogramOverrides(in AdSelectionOverrideCallback callback); 288 } 289