CustomAudienceManager


public class CustomAudienceManager
extends Object

java.lang.Object
   ↳ android.adservices.customaudience.CustomAudienceManager


CustomAudienceManager provides APIs for app and ad-SDKs to join / leave custom audiences.

Summary

Public methods

void fetchAndJoinCustomAudience(FetchAndJoinCustomAudienceRequest fetchAndJoinCustomAudienceRequest, Executor executor, OutcomeReceiver<ObjectException> receiver)

Adds the user to the CustomAudience fetched from a fetchUri.

static CustomAudienceManager get(Context context)

Factory method for creating an instance of CustomAudienceManager.

TestCustomAudienceManager getTestCustomAudienceManager()

Create a service with test-enabling APIs

void joinCustomAudience(JoinCustomAudienceRequest joinCustomAudienceRequest, Executor executor, OutcomeReceiver<ObjectException> receiver)

Adds the user to the given CustomAudience.

void leaveCustomAudience(LeaveCustomAudienceRequest leaveCustomAudienceRequest, Executor executor, OutcomeReceiver<ObjectException> receiver)

Attempts to remove a user from a custom audience by deleting any existing CustomAudience data, identified by ownerPackageName, buyer, and name.

Inherited methods

Public methods

fetchAndJoinCustomAudience

public void fetchAndJoinCustomAudience (FetchAndJoinCustomAudienceRequest fetchAndJoinCustomAudienceRequest, 
                Executor executor, 
                OutcomeReceiver<ObjectException> receiver)

Adds the user to the CustomAudience fetched from a fetchUri.

An attempt to register the user for a custom audience with the same combination of ownerPackageName, buyer, and name will cause the existing custom audience's information to be overwritten, including the list of ads data.

Note that the ads list can be completely overwritten by the daily background fetch job.

This call fails with an SecurityException if

  1. the ownerPackageName is not calling app's package name and/or
  2. the buyer is not authorized to use the API.

This call fails with an IllegalArgumentException if

  1. the storage limit has been exceeded by the calling application and/or
  2. any URI parameters in the CustomAudience given are not authenticated with the CustomAudience buyer.

This call fails with LimitExceededException if the calling package exceeds the allowed rate limits and is throttled.

This call fails with an IllegalStateException if an internal service error is encountered.
Requires AdServicesPermissions.ACCESS_ADSERVICES_CUSTOM_AUDIENCE

Parameters
fetchAndJoinCustomAudienceRequest FetchAndJoinCustomAudienceRequest: This value cannot be null.

executor Executor: This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

receiver OutcomeReceiver: This value cannot be null.

get

public static CustomAudienceManager get (Context context)

Factory method for creating an instance of CustomAudienceManager.

Parameters
context Context: The Context to use This value cannot be null.

Returns
CustomAudienceManager A CustomAudienceManager instance This value cannot be null.

getTestCustomAudienceManager

public TestCustomAudienceManager getTestCustomAudienceManager ()

Create a service with test-enabling APIs

Returns
TestCustomAudienceManager This value cannot be null.

joinCustomAudience

public void joinCustomAudience (JoinCustomAudienceRequest joinCustomAudienceRequest, 
                Executor executor, 
                OutcomeReceiver<ObjectException> receiver)

Adds the user to the given CustomAudience.

An attempt to register the user for a custom audience with the same combination of ownerPackageName, buyer, and name will cause the existing custom audience's information to be overwritten, including the list of ads data.

Note that the ads list can be completely overwritten by the daily background fetch job.

This call fails with an SecurityException if

  1. the ownerPackageName is not calling app's package name and/or
  2. the buyer is not authorized to use the API.

This call fails with an IllegalArgumentException if

  1. the storage limit has been exceeded by the calling application and/or
  2. any URI parameters in the CustomAudience given are not authenticated with the CustomAudience buyer.

This call fails with LimitExceededException if the calling package exceeds the allowed rate limits and is throttled.

This call fails with an IllegalStateException if an internal service error is encountered.
Requires AdServicesPermissions.ACCESS_ADSERVICES_CUSTOM_AUDIENCE

Parameters
joinCustomAudienceRequest JoinCustomAudienceRequest: This value cannot be null.

executor Executor: This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

receiver OutcomeReceiver: This value cannot be null.

leaveCustomAudience

public void leaveCustomAudience (LeaveCustomAudienceRequest leaveCustomAudienceRequest, 
                Executor executor, 
                OutcomeReceiver<ObjectException> receiver)

Attempts to remove a user from a custom audience by deleting any existing CustomAudience data, identified by ownerPackageName, buyer, and name.

This call fails with an SecurityException if

  1. the ownerPackageName is not calling app's package name; and/or
  2. the buyer is not authorized to use the API.

This call fails with LimitExceededException if the calling package exceeds the allowed rate limits and is throttled.

This call does not inform the caller whether the custom audience specified existed in on-device storage. In other words, it will fail silently when a buyer attempts to leave a custom audience that was not joined.
Requires AdServicesPermissions.ACCESS_ADSERVICES_CUSTOM_AUDIENCE

Parameters
leaveCustomAudienceRequest LeaveCustomAudienceRequest: This value cannot be null.

executor Executor: This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

receiver OutcomeReceiver: This value cannot be null.