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.common.AdSelectionSignals; 20 import android.annotation.FlaggedApi; 21 import android.annotation.NonNull; 22 import android.os.OutcomeReceiver; 23 24 import com.android.adservices.flags.Flags; 25 26 import java.util.Objects; 27 import java.util.concurrent.Executor; 28 29 /** 30 * This POJO represents the {@link 31 * TestAdSelectionManager#overrideAdSelectionConfigRemoteInfo(AddAdSelectionOverrideRequest, 32 * Executor, OutcomeReceiver)} request 33 * 34 * <p>It contains, a {@link AdSelectionConfig} which will serve as the identifier for the specific 35 * override, a {@code String} decisionLogicJs and {@code String} trustedScoringSignals field 36 * representing the override value 37 */ 38 public class AddAdSelectionOverrideRequest { 39 @NonNull private final AdSelectionConfig mAdSelectionConfig; 40 41 @NonNull private final String mDecisionLogicJs; 42 43 @NonNull private final AdSelectionSignals mTrustedScoringSignals; 44 45 @NonNull private final PerBuyerDecisionLogic mPerBuyerDecisionLogic; 46 47 /** 48 * Builds a {@link AddAdSelectionOverrideRequest} instance. 49 * 50 * @param adSelectionConfig configuration for ad selection. See {@link AdSelectionConfig} 51 * @param decisionLogicJs override for scoring logic. See {@link 52 * AdSelectionConfig#getDecisionLogicUri()} 53 * @param trustedScoringSignals override for trusted seller signals. See {@link 54 * AdSelectionConfig#getTrustedScoringSignalsUri()} 55 * @param perBuyerDecisionLogic override for buyer's reporting logic for contextual ads. See 56 * {@link SignedContextualAds#getDecisionLogicUri()} 57 */ 58 @FlaggedApi(Flags.FLAG_FLEDGE_AD_SELECTION_FILTERING_ENABLED) AddAdSelectionOverrideRequest( @onNull AdSelectionConfig adSelectionConfig, @NonNull String decisionLogicJs, @NonNull AdSelectionSignals trustedScoringSignals, @NonNull PerBuyerDecisionLogic perBuyerDecisionLogic)59 public AddAdSelectionOverrideRequest( 60 @NonNull AdSelectionConfig adSelectionConfig, 61 @NonNull String decisionLogicJs, 62 @NonNull AdSelectionSignals trustedScoringSignals, 63 @NonNull PerBuyerDecisionLogic perBuyerDecisionLogic) { 64 Objects.requireNonNull(adSelectionConfig); 65 Objects.requireNonNull(decisionLogicJs); 66 Objects.requireNonNull(trustedScoringSignals); 67 Objects.requireNonNull(perBuyerDecisionLogic); 68 69 mAdSelectionConfig = adSelectionConfig; 70 mDecisionLogicJs = decisionLogicJs; 71 mTrustedScoringSignals = trustedScoringSignals; 72 mPerBuyerDecisionLogic = perBuyerDecisionLogic; 73 } 74 75 /** 76 * Builds a {@link AddAdSelectionOverrideRequest} instance. 77 * 78 * @param adSelectionConfig configuration for ad selection. See {@link AdSelectionConfig} 79 * @param decisionLogicJs override for scoring logic. See {@link 80 * AdSelectionConfig#getDecisionLogicUri()} 81 * @param trustedScoringSignals override for trusted seller signals. See {@link 82 * AdSelectionConfig#getTrustedScoringSignalsUri()} 83 */ AddAdSelectionOverrideRequest( @onNull AdSelectionConfig adSelectionConfig, @NonNull String decisionLogicJs, @NonNull AdSelectionSignals trustedScoringSignals)84 public AddAdSelectionOverrideRequest( 85 @NonNull AdSelectionConfig adSelectionConfig, 86 @NonNull String decisionLogicJs, 87 @NonNull AdSelectionSignals trustedScoringSignals) { 88 this( 89 adSelectionConfig, 90 decisionLogicJs, 91 trustedScoringSignals, 92 PerBuyerDecisionLogic.EMPTY); 93 } 94 95 /** 96 * @return an instance of {@link AdSelectionConfig}, the configuration of the ad selection 97 * process. This configuration provides the data necessary to run Ad Selection flow that 98 * generates bids and scores to find a wining ad for rendering. 99 */ 100 @NonNull getAdSelectionConfig()101 public AdSelectionConfig getAdSelectionConfig() { 102 return mAdSelectionConfig; 103 } 104 105 /** 106 * @return The override javascript result, should be a string that contains valid JS code. The 107 * code should contain the scoring logic that will be executed during Ad selection. 108 */ 109 @NonNull getDecisionLogicJs()110 public String getDecisionLogicJs() { 111 return mDecisionLogicJs; 112 } 113 114 /** 115 * @return The override trusted scoring signals, should be a valid json string. The trusted 116 * signals would be fed into the scoring logic during Ad Selection. 117 */ 118 @NonNull getTrustedScoringSignals()119 public AdSelectionSignals getTrustedScoringSignals() { 120 return mTrustedScoringSignals; 121 } 122 123 /** 124 * @return The override for the decision logic for each buyer that is used by contextual ads for 125 * reporting, which may be extended to updating bid values for contextual ads in the future 126 */ 127 @FlaggedApi(Flags.FLAG_FLEDGE_AD_SELECTION_FILTERING_ENABLED) 128 @NonNull getPerBuyerDecisionLogic()129 public PerBuyerDecisionLogic getPerBuyerDecisionLogic() { 130 return mPerBuyerDecisionLogic; 131 } 132 } 133