/* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.adservices.adselection; import android.adservices.common.AdSelectionSignals; import android.adservices.common.AdTechIdentifier; import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; import com.android.adservices.AdServicesParcelableUtil; import com.android.adservices.flags.Flags; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; /** * Contains the configuration of the ad selection process. * *
Instances of this class are created by SDKs to be provided as arguments to the {@link
* AdSelectionManager#selectAds} and {@link AdSelectionManager#reportImpression} methods in {@link
* AdSelectionManager}.
*/
// TODO(b/233280314): investigate on adSelectionConfig optimization by merging mCustomAudienceBuyers
// and mPerBuyerSignals.
public final class AdSelectionConfig implements Parcelable {
/**
* {@link AdSelectionConfig} with empty values for each field.
*
* @hide
*/
@NonNull public static final AdSelectionConfig EMPTY = new AdSelectionConfig();
@NonNull private final AdTechIdentifier mSeller;
@NonNull private final Uri mDecisionLogicUri;
@NonNull private final List See {@link #getSeller()} for more details.
*/
@NonNull
public AdSelectionConfig.Builder setSeller(@NonNull AdTechIdentifier seller) {
Objects.requireNonNull(seller);
this.mSeller = seller;
return this;
}
/**
* Sets the URI used to fetch decision logic for use in the ad selection process. Decision
* URI could be either of the two schemas:
*
* Available prebuilt scripts:
* Ex. If your base reporting URL is "https://www.ssp.com" then, {@code
* ad-selection-prebuilt://ad-selection/highest-bid-wins/?reportingUrl=https://www.ssp.com}
* See {@link #getDecisionLogicUri()} for more details.
*/
@NonNull
public AdSelectionConfig.Builder setDecisionLogicUri(@NonNull Uri decisionLogicUri) {
Objects.requireNonNull(decisionLogicUri);
this.mDecisionLogicUri = decisionLogicUri;
return this;
}
/**
* Sets the list of allowed buyers.
*
* See {@link #getCustomAudienceBuyers()} for more details.
*/
@NonNull
public AdSelectionConfig.Builder setCustomAudienceBuyers(
@NonNull List If not set, defaults to the empty JSON.
*
* See {@link #getAdSelectionSignals()} for more details.
*/
@NonNull
public AdSelectionConfig.Builder setAdSelectionSignals(
@NonNull AdSelectionSignals adSelectionSignals) {
Objects.requireNonNull(adSelectionSignals);
this.mAdSelectionSignals = adSelectionSignals;
return this;
}
/**
* Set the signals used to modify ad selection results.
*
* If not set, defaults to the empty JSON.
*
* See {@link #getSellerSignals()} for more details.
*/
@NonNull
public AdSelectionConfig.Builder setSellerSignals(
@NonNull AdSelectionSignals sellerSignals) {
Objects.requireNonNull(sellerSignals);
this.mSellerSignals = sellerSignals;
return this;
}
/**
* Sets the signals provided by each buyer during ad selection.
*
* If not set, defaults to an empty map.
*
* See {@link #getPerBuyerSignals()} for more details.
*/
@NonNull
public AdSelectionConfig.Builder setPerBuyerSignals(
@NonNull Map If not set, defaults to an empty map.
*
* See {@link #getPerBuyerSignedContextualAds()} for more details.
*/
@FlaggedApi(Flags.FLAG_FLEDGE_AD_SELECTION_FILTERING_ENABLED)
@NonNull
public AdSelectionConfig.Builder setPerBuyerSignedContextualAds(
@NonNull Map If {@link Uri#EMPTY} is passed then network call will be skipped and {@link
* AdSelectionSignals#EMPTY} will be passed to ad selection.
*
* See {@link #getTrustedScoringSignalsUri()} for more details.
*/
@NonNull
public AdSelectionConfig.Builder setTrustedScoringSignalsUri(
@NonNull Uri trustedScoringSignalsUri) {
Objects.requireNonNull(trustedScoringSignalsUri);
this.mTrustedScoringSignalsUri = trustedScoringSignalsUri;
return this;
}
/**
* Builds an {@link AdSelectionConfig} instance.
*
* @throws NullPointerException if any required params are null
*/
@NonNull
public AdSelectionConfig build() {
Objects.requireNonNull(mSeller, "The seller has not been provided");
Objects.requireNonNull(
mDecisionLogicUri, "The decision logic URI has not been provided");
Objects.requireNonNull(
mCustomAudienceBuyers, "The custom audience buyers have not been provided");
Objects.requireNonNull(
mAdSelectionSignals, "The ad selection signals have not been provided");
Objects.requireNonNull(mSellerSignals, "The seller signals have not been provided");
Objects.requireNonNull(
mPerBuyerSignals, "The per buyer signals have not been provided");
Objects.requireNonNull(
mBuyerSignedContextualAds,
"The buyer signed contextual ads have not been provided");
Objects.requireNonNull(
mTrustedScoringSignalsUri,
"The trusted scoring signals URI have not been provided");
return new AdSelectionConfig(
mSeller,
mDecisionLogicUri,
mCustomAudienceBuyers,
mAdSelectionSignals,
mSellerSignals,
mPerBuyerSignals,
mBuyerSignedContextualAds,
mTrustedScoringSignalsUri);
}
}
}
*
*
*
*
*
*
*