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 android.adservices.common.AdTechIdentifier; 20 import android.annotation.Nullable; 21 import android.net.Uri; 22 23 import androidx.annotation.NonNull; 24 import androidx.room.ColumnInfo; 25 import androidx.room.Entity; 26 import androidx.room.Index; 27 import androidx.room.TypeConverters; 28 29 import com.android.adservices.data.common.FledgeRoomConverters; 30 31 import com.google.auto.value.AutoValue; 32 import com.google.auto.value.AutoValue.CopyAnnotations; 33 34 import java.util.Objects; 35 import java.util.Set; 36 37 /** Table to look up auction server ad selection data. */ 38 @AutoValue 39 @CopyAnnotations 40 @Entity( 41 tableName = "auction_server_ad_selection", 42 indices = {@Index(value = {"ad_selection_id"})}, 43 primaryKeys = {"ad_selection_id"}) 44 @TypeConverters({FledgeRoomConverters.class}) 45 public abstract class DBAuctionServerAdSelection { 46 /** The id associated with this auction. */ 47 @CopyAnnotations 48 @ColumnInfo(name = "ad_selection_id") getAdSelectionId()49 public abstract long getAdSelectionId(); 50 51 /** The seller ad tech who requested this auction. */ 52 @CopyAnnotations 53 @NonNull 54 @ColumnInfo(name = "seller") getSeller()55 public abstract AdTechIdentifier getSeller(); 56 57 /** The buyer ad tech who won this auction. */ 58 @CopyAnnotations 59 @Nullable 60 @ColumnInfo(name = "winner_buyer") getWinnerBuyer()61 public abstract AdTechIdentifier getWinnerBuyer(); 62 63 /** 64 * The winner ad render uri for this auction. 65 * 66 * <p>Sets {@link Uri#EMPTY} if no remarketing winner 67 */ 68 @CopyAnnotations 69 @Nullable 70 @ColumnInfo(name = "winner_ad_render_uri") getWinnerAdRenderUri()71 public abstract Uri getWinnerAdRenderUri(); 72 73 /** Ad counter keys for histogram reporting */ 74 @CopyAnnotations 75 @Nullable 76 @ColumnInfo(name = "ad_counter_int_keys") getAdCounterIntKeys()77 public abstract Set<Integer> getAdCounterIntKeys(); 78 79 // TODO(b/287157063): Add beacon for interaction reporting 80 81 /** The reporting uri associated with seller. */ 82 @CopyAnnotations 83 @Nullable 84 @ColumnInfo(name = "seller_win_reporting_uri") getSellerReportingUri()85 public abstract Uri getSellerReportingUri(); 86 87 /** The reporting uri associated with auction winner/buyer. */ 88 @CopyAnnotations 89 @Nullable 90 @ColumnInfo(name = "buyer_win_reporting_uri") getBuyerReportingUri()91 public abstract Uri getBuyerReportingUri(); 92 93 /** Returns an AutoValue builder for a {@link DBAuctionServerAdSelection} entity. */ 94 @NonNull builder()95 public static DBAuctionServerAdSelection.Builder builder() { 96 return new AutoValue_DBAuctionServerAdSelection.Builder(); 97 } 98 99 /** 100 * Creates a {@link DBAuctionServerAdSelection} object using the builder. 101 * 102 * <p>Required for Room SQLite integration. 103 */ 104 @NonNull create( long adSelectionId, @NonNull AdTechIdentifier seller, @Nullable AdTechIdentifier winnerBuyer, @Nullable Uri winnerAdRenderUri, @Nullable Set<Integer> adCounterIntKeys, @Nullable Uri sellerReportingUri, @Nullable Uri buyerReportingUri)105 public static DBAuctionServerAdSelection create( 106 long adSelectionId, 107 @NonNull AdTechIdentifier seller, 108 @Nullable AdTechIdentifier winnerBuyer, 109 @Nullable Uri winnerAdRenderUri, 110 @Nullable Set<Integer> adCounterIntKeys, 111 @Nullable Uri sellerReportingUri, 112 @Nullable Uri buyerReportingUri) { 113 Objects.requireNonNull(seller); 114 115 return builder() 116 .setAdSelectionId(adSelectionId) 117 .setSeller(seller) 118 .setWinnerBuyer(winnerBuyer) 119 .setWinnerAdRenderUri(winnerAdRenderUri) 120 .setAdCounterIntKeys(adCounterIntKeys) 121 .setSellerReportingUri(sellerReportingUri) 122 .setBuyerReportingUri(buyerReportingUri) 123 .build(); 124 } 125 126 /** Builder class for a {@link DBAuctionServerAdSelection}. */ 127 @AutoValue.Builder 128 public abstract static class Builder { 129 /** Sets ad selection id. */ setAdSelectionId(long adSelectionId)130 public abstract DBAuctionServerAdSelection.Builder setAdSelectionId(long adSelectionId); 131 132 /** Sets seller ad tech. */ setSeller( @onNull AdTechIdentifier seller)133 public abstract DBAuctionServerAdSelection.Builder setSeller( 134 @NonNull AdTechIdentifier seller); 135 136 /** Sets seller ad tech. */ setWinnerBuyer( @ullable AdTechIdentifier winningBuyer)137 public abstract DBAuctionServerAdSelection.Builder setWinnerBuyer( 138 @Nullable AdTechIdentifier winningBuyer); 139 140 /** Sets ad render uri. */ setWinnerAdRenderUri( @ullable Uri winnerAdRenderUri)141 public abstract DBAuctionServerAdSelection.Builder setWinnerAdRenderUri( 142 @Nullable Uri winnerAdRenderUri); 143 144 /** Sets ad counter keys */ setAdCounterIntKeys( @ullable Set<Integer> adCounterIntKeys)145 public abstract DBAuctionServerAdSelection.Builder setAdCounterIntKeys( 146 @Nullable Set<Integer> adCounterIntKeys); 147 148 /** Sets seller reporting uri. */ setSellerReportingUri( @ullable Uri sellerReportingUri)149 public abstract DBAuctionServerAdSelection.Builder setSellerReportingUri( 150 @Nullable Uri sellerReportingUri); 151 152 /** Sets buyer reporting uri. */ setBuyerReportingUri( @ullable Uri buyerReportingUri)153 public abstract DBAuctionServerAdSelection.Builder setBuyerReportingUri( 154 @Nullable Uri buyerReportingUri); 155 156 /** Builds the {@link DBAuctionServerAdSelection}. */ build()157 public abstract DBAuctionServerAdSelection build(); 158 } 159 } 160