AdSelectionManagerFutures


abstract class AdSelectionManagerFutures


This class provides APIs to select ads and report impressions. This class can be used by Java clients.

Summary

Public companion functions

AdSelectionManagerFutures?
from(context: Context)

Creates AdSelectionManagerFutures.

Public functions

abstract ListenableFuture<GetAdSelectionDataOutcome>
@ExperimentalFeatures.Ext10OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
getAdSelectionDataAsync(
    getAdSelectionDataRequest: GetAdSelectionDataRequest
)

Collects custom audience data from device.

abstract ListenableFuture<AdSelectionOutcome>
@ExperimentalFeatures.Ext10OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
persistAdSelectionResultAsync(
    persistAdSelectionResultRequest: PersistAdSelectionResultRequest
)

Persists the ad selection results from the server-side.

abstract ListenableFuture<Unit>
@ExperimentalFeatures.Ext8OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
reportEventAsync(reportEventRequest: ReportEventRequest)

Notifies the service that there is a new ad event to report for the ad selected by the ad-selection run identified by {@code adSelectionId}.

abstract ListenableFuture<Unit>
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
reportImpressionAsync(reportImpressionRequest: ReportImpressionRequest)

Report the given impression.

abstract ListenableFuture<AdSelectionOutcome>
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
selectAdsAsync(adSelectionConfig: AdSelectionConfig)

Runs the ad selection process on device to select a remarketing ad for the caller application.

abstract ListenableFuture<AdSelectionOutcome>
@ExperimentalFeatures.Ext10OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
selectAdsAsync(
    adSelectionFromOutcomesConfig: AdSelectionFromOutcomesConfig
)

Selects an ad from the results of previously ran ad selections.

abstract ListenableFuture<Unit>
@ExperimentalFeatures.Ext8OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
updateAdCounterHistogramAsync(
    updateAdCounterHistogramRequest: UpdateAdCounterHistogramRequest
)

Updates the counter histograms for an ad which was previously selected by a call to selectAdsAsync.

Public companion functions

from

Added in 1.0.0
fun from(context: Context): AdSelectionManagerFutures?

Creates AdSelectionManagerFutures.

Returns
AdSelectionManagerFutures?

AdSelectionManagerFutures object. If the device is running an incompatible build, the value returned is null.

Public functions

getAdSelectionDataAsync

Added in 1.1.0-beta06
@ExperimentalFeatures.Ext10OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
abstract fun getAdSelectionDataAsync(
    getAdSelectionDataRequest: GetAdSelectionDataRequest
): ListenableFuture<GetAdSelectionDataOutcome>

Collects custom audience data from device. Returns a compressed and encrypted blob to send to auction servers for ad selection.

Custom audience ads must have a {@code ad_render_id} to be eligible for to be collected.

See AdSelectionManager#persistAdSelectionResult for how to process the results of the ad selection run on server-side with the blob generated by this API.

The output is passed by the receiver, which either returns an GetAdSelectionDataOutcome for a successful run, or an Exception includes the type of the exception thrown and the corresponding error message.

If the IllegalArgumentException is thrown, it is caused by invalid input argument the API received to run the ad selection.

If the IllegalStateException is thrown with error message "Failure of AdSelection services.", it is caused by an internal failure of the ad selection service.

If the TimeoutException is thrown, it is caused when a timeout is encountered during bidding, scoring, or overall selection process to find winning Ad.

If the LimitExceededException is thrown, it is caused when the calling package exceeds the allowed rate limits and is throttled.

If the SecurityException is thrown, it is caused when the caller is not authorized or permission is not requested.

If the UnsupportedOperationException is thrown, it is caused when the Android API level and AdServices module versions don't support this API.

Parameters
getAdSelectionDataRequest: GetAdSelectionDataRequest

the request for get ad selection data.

persistAdSelectionResultAsync

Added in 1.1.0-beta06
@ExperimentalFeatures.Ext10OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
abstract fun persistAdSelectionResultAsync(
    persistAdSelectionResultRequest: PersistAdSelectionResultRequest
): ListenableFuture<AdSelectionOutcome>

Persists the ad selection results from the server-side.

See AdSelectionManager#getAdSelectionData for how to generate an encrypted blob to run an ad selection on the server side.

The output is passed by the receiver, which either returns an AdSelectionOutcome for a successful run, or an Exception includes the type of the exception thrown and the corresponding error message.

If the IllegalArgumentException is thrown, it is caused by invalid input argument the API received to run the ad selection.

If the IllegalStateException is thrown with error message "Failure of AdSelection services.", it is caused by an internal failure of the ad selection service.

If the TimeoutException is thrown, it is caused when a timeout is encountered during bidding, scoring, or overall selection process to find winning Ad.

If the LimitExceededException is thrown, it is caused when the calling package exceeds the allowed rate limits and is throttled.

If the SecurityException is thrown, it is caused when the caller is not authorized or permission is not requested.

If the UnsupportedOperationException is thrown, it is caused when the Android API level and AdServices module versions don't support this API.

Parameters
persistAdSelectionResultRequest: PersistAdSelectionResultRequest

the request for persist ad selection result.

reportEventAsync

Added in 1.1.0-beta06
@ExperimentalFeatures.Ext8OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
abstract fun reportEventAsync(reportEventRequest: ReportEventRequest): ListenableFuture<Unit>

Notifies the service that there is a new ad event to report for the ad selected by the ad-selection run identified by {@code adSelectionId}. An ad event is any occurrence that happens to an ad associated with the given {@code adSelectionId}. There is no guarantee about when the ad event will be reported. The event reporting could be delayed and reports could be batched.

Using ReportEventRequest#getKey(), the service will fetch the {@code reportingUri} that was registered in {@code registerAdBeacon}. See documentation of reportImpressionAsync for more details regarding {@code registerAdBeacon}. Then, the service will attach ReportEventRequest#getData() to the request body of a POST request and send the request. The body of the POST request will have the {@code content-type} of {@code text/plain}, and the data will be transmitted in {@code charset=UTF-8}.

The output is passed by the receiver, which either returns an empty Object for a successful run, or an Exception includes the type of the exception thrown and the corresponding error message.

If the IllegalArgumentException is thrown, it is caused by invalid input argument the API received to report the ad event.

If the IllegalStateException is thrown with error message "Failure of AdSelection services.", it is caused by an internal failure of the ad selection service.

If the LimitExceededException is thrown, it is caused when the calling package exceeds the allowed rate limits and is throttled.

If the SecurityException is thrown, it is caused when the caller is not authorized or permission is not requested.

If the UnsupportedOperationException is thrown, it is caused when the Android API level and AdServices module versions don't support this API.

Events will be reported at most once as a best-effort attempt.

Parameters
reportEventRequest: ReportEventRequest

the request for reporting event.

reportImpressionAsync

Added in 1.0.0
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
abstract fun reportImpressionAsync(reportImpressionRequest: ReportImpressionRequest): ListenableFuture<Unit>

Report the given impression. The ReportImpressionRequest is provided by the Ads SDK. The receiver either returns a {@code void} for a successful run, or an Exception indicates the error.

If the IllegalArgumentException is thrown, it is caused by invalid input argument the API received to report the impression.

If the IllegalStateException is thrown with error message "Failure of AdSelection services.", it is caused by an internal failure of the ad selection service.

If the LimitExceededException is thrown, it is caused when the calling package exceeds the allowed rate limits and is throttled.

If the SecurityException is thrown, it is caused when the caller is not authorized or permission is not requested.

If the UnsupportedOperationException is thrown, it is caused when the Android API level and AdServices module versions don't support ReportImpressionRequest with null {@code AdSelectionConfig}

Parameters
reportImpressionRequest: ReportImpressionRequest

the request for reporting impression.

selectAdsAsync

Added in 1.0.0
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
abstract fun selectAdsAsync(adSelectionConfig: AdSelectionConfig): ListenableFuture<AdSelectionOutcome>

Runs the ad selection process on device to select a remarketing ad for the caller application.

Parameters
adSelectionConfig: AdSelectionConfig

the config The input {@code adSelectionConfig} is provided by the Ads SDK and the AdSelectionConfig object is transferred via a Binder call. For this reason, the total size of these objects is bound to the Android IPC limitations. Failures to transfer the AdSelectionConfig will throws an TransactionTooLargeException.

The output is passed by the receiver, which either returns an AdSelectionOutcome for a successful run, or an Exception includes the type of the exception thrown and the corresponding error message.

If the IllegalArgumentException is thrown, it is caused by invalid input argument the API received to run the ad selection.

If the IllegalStateException is thrown with error message "Failure of AdSelection services.", it is caused by an internal failure of the ad selection service.

If the TimeoutException is thrown, it is caused when a timeout is encountered during bidding, scoring, or overall selection process to find winning Ad.

If the LimitExceededException is thrown, it is caused when the calling package exceeds the allowed rate limits and is throttled.

selectAdsAsync

Added in 1.1.0-beta06
@ExperimentalFeatures.Ext10OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
abstract fun selectAdsAsync(
    adSelectionFromOutcomesConfig: AdSelectionFromOutcomesConfig
): ListenableFuture<AdSelectionOutcome>

Selects an ad from the results of previously ran ad selections.

Parameters
adSelectionFromOutcomesConfig: AdSelectionFromOutcomesConfig

is provided by the Ads SDK and the AdSelectionFromOutcomesConfig object is transferred via a Binder call. For this reason, the total size of these objects is bound to the Android IPC limitations. Failures to transfer the AdSelectionFromOutcomesConfig will throw an TransactionTooLargeException.

The output is passed by the receiver, which either returns an AdSelectionOutcome for a successful run, or an Exception includes the type of the exception thrown and the corresponding error message.

If the IllegalArgumentException is thrown, it is caused by invalid input argument the API received to run the ad selection.

If the IllegalStateException is thrown with error message "Failure of AdSelection services.", it is caused by an internal failure of the ad selection service.

If the TimeoutException is thrown, it is caused when a timeout is encountered during bidding, scoring, or overall selection process to find winning Ad.

If the LimitExceededException is thrown, it is caused when the calling package exceeds the allowed rate limits and is throttled.

If the SecurityException is thrown, it is caused when the caller is not authorized or permission is not requested.

If the UnsupportedOperationException is thrown, it is caused when the Android API level and AdServices module versions don't support this API.

updateAdCounterHistogramAsync

Added in 1.1.0-beta06
@ExperimentalFeatures.Ext8OptIn
@RequiresPermission(value = "android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE")
abstract fun updateAdCounterHistogramAsync(
    updateAdCounterHistogramRequest: UpdateAdCounterHistogramRequest
): ListenableFuture<Unit>

Updates the counter histograms for an ad which was previously selected by a call to selectAdsAsync.

The counter histograms are used in ad selection to inform frequency cap filtering on candidate ads, where ads whose frequency caps are met or exceeded are removed from the bidding process during ad selection.

Counter histograms can only be updated for ads specified by the given {@code adSelectionId} returned by a recent call to Protected Audience API ad selection from the same caller app.

A SecurityException is returned if:

  1. the app has not declared the correct permissions in its manifest, or
  2. the app or entity identified by the {@code callerAdTechIdentifier} are not authorized to use the API.

An IllegalStateException is returned if the call does not come from an app with a foreground activity.

A LimitExceededException is returned if the call exceeds the calling app's API throttle.

An UnsupportedOperationException is returned if the Android API level and AdServices module versions don't support this API.

In all other failure cases, it will return an empty Object. Note that to protect user privacy, internal errors will not be sent back via an exception.

Parameters
updateAdCounterHistogramRequest: UpdateAdCounterHistogramRequest

the request for updating the ad counter histogram.