1 /* 2 * Copyright (C) 2023 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 com.android.adservices.data.adselection; 18 19 import static com.google.auto.value.AutoValue.CopyAnnotations; 20 21 import android.adservices.adselection.DecisionLogic; 22 import android.adservices.common.AdTechIdentifier; 23 24 import androidx.annotation.NonNull; 25 import androidx.room.ColumnInfo; 26 import androidx.room.Entity; 27 28 import com.google.auto.value.AutoValue; 29 30 /** This POJO represents the {@link DecisionLogic} entity associated with an Ad Selection */ 31 @AutoValue 32 @CopyAnnotations 33 @Entity( 34 tableName = "ad_selection_buyer_logic_overrides", 35 primaryKeys = {"ad_selection_config_id", "buyer_identifier"}) 36 public abstract class DBBuyerDecisionOverride { 37 /** @return AdSelectionConfigId, the primary key of this table */ 38 @CopyAnnotations 39 @ColumnInfo(name = "ad_selection_config_id") 40 @NonNull getAdSelectionConfigId()41 public abstract String getAdSelectionConfigId(); 42 43 /** @return App package name */ 44 @CopyAnnotations 45 @ColumnInfo(name = "app_package_name") 46 @NonNull getAppPackageName()47 public abstract String getAppPackageName(); 48 49 /** @return buyers associated with the override */ 50 @CopyAnnotations 51 @ColumnInfo(name = "buyer_identifier") 52 @NonNull getBuyer()53 public abstract AdTechIdentifier getBuyer(); 54 55 /** @return The override javascript result */ 56 @CopyAnnotations 57 @ColumnInfo(name = "decision_logic") 58 @NonNull getDecisionLogic()59 public abstract String getDecisionLogic(); 60 61 /** Creates an instance of {@link DBBuyerDecisionOverride} */ create( String adSelectionConfigId, String appPackageName, AdTechIdentifier buyer, String decisionLogic)62 public static DBBuyerDecisionOverride create( 63 String adSelectionConfigId, 64 String appPackageName, 65 AdTechIdentifier buyer, 66 String decisionLogic) { 67 return builder() 68 .setAdSelectionConfigId(adSelectionConfigId) 69 .setAppPackageName(appPackageName) 70 .setBuyer(buyer) 71 .setDecisionLogic(decisionLogic) 72 .build(); 73 } 74 75 /** Builds an instance of {@link DBBuyerDecisionOverride} */ builder()76 public static DBBuyerDecisionOverride.Builder builder() { 77 return new AutoValue_DBBuyerDecisionOverride.Builder(); 78 } 79 80 /** A builder to create an instance of {@link DBBuyerDecisionOverride} */ 81 @AutoValue.Builder 82 public abstract static class Builder { 83 84 /** Sets the ID for the {@link DBBuyerDecisionOverride} entry. */ setAdSelectionConfigId( String adSelectionConfigId)85 public abstract DBBuyerDecisionOverride.Builder setAdSelectionConfigId( 86 String adSelectionConfigId); 87 88 /** Sets the Package Name of the app creating the override. */ setAppPackageName(String appPackageName)89 public abstract DBBuyerDecisionOverride.Builder setAppPackageName(String appPackageName); 90 91 /** Sets the buyer associated with this override */ setBuyer(AdTechIdentifier buyer)92 public abstract DBBuyerDecisionOverride.Builder setBuyer(AdTechIdentifier buyer); 93 94 /** Sets the Buyer decision logic to use instead of fetching it from a trusted server. */ setDecisionLogic( String perBuyerDecisionLogic)95 public abstract DBBuyerDecisionOverride.Builder setDecisionLogic( 96 String perBuyerDecisionLogic); 97 98 /** @return an instance of {@link DBBuyerDecisionOverride} */ build()99 public abstract DBBuyerDecisionOverride build(); 100 } 101 } 102