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.NonNull; 21 import android.annotation.Nullable; 22 23 import androidx.room.ColumnInfo; 24 import androidx.room.Entity; 25 import androidx.room.Index; 26 import androidx.room.TypeConverters; 27 28 import com.android.adservices.data.common.FledgeRoomConverters; 29 30 import com.google.auto.value.AutoValue; 31 32 import java.time.Instant; 33 import java.util.Objects; 34 35 /** Table to persist records related to start of an ad selection run. */ 36 @AutoValue 37 @AutoValue.CopyAnnotations 38 @Entity( 39 tableName = "ad_selection_initialization", 40 indices = {@Index(value = {"ad_selection_id", "caller_package_name"})}, 41 primaryKeys = {"ad_selection_id"}) 42 @TypeConverters({FledgeRoomConverters.class}) 43 public abstract class DBAdSelectionInitialization { 44 45 /** The id associated with this auction. */ 46 @AutoValue.CopyAnnotations 47 @ColumnInfo(name = "ad_selection_id") getAdSelectionId()48 public abstract long getAdSelectionId(); 49 50 /** The creation time for this ad selection run. */ 51 @AutoValue.CopyAnnotations 52 @NonNull 53 @ColumnInfo(name = "creation_instant") getCreationInstant()54 public abstract Instant getCreationInstant(); 55 56 /** The seller ad tech who requested this auction. */ 57 @AutoValue.CopyAnnotations 58 @Nullable 59 @ColumnInfo(name = "seller") getSeller()60 public abstract AdTechIdentifier getSeller(); 61 62 /** The caller package which initiated this ad selection run. */ 63 @AutoValue.CopyAnnotations 64 @Nullable 65 @ColumnInfo(name = "caller_package_name") getCallerPackageName()66 public abstract String getCallerPackageName(); 67 68 /** Returns an AutoValue builder for a {@link DBAdSelectionInitialization} entity. */ 69 @NonNull builder()70 public static DBAdSelectionInitialization.Builder builder() { 71 return new AutoValue_DBAdSelectionInitialization.Builder(); 72 } 73 74 /** 75 * Creates a {@link DBAdSelectionInitialization} object using the builder. 76 * 77 * <p>Required for Room SQLite integration. 78 */ 79 @NonNull create( long adSelectionId, @NonNull Instant creationInstant, @Nullable AdTechIdentifier seller, @Nullable String callerPackageName)80 public static DBAdSelectionInitialization create( 81 long adSelectionId, 82 @NonNull Instant creationInstant, 83 @Nullable AdTechIdentifier seller, 84 @Nullable String callerPackageName) { 85 Objects.requireNonNull(creationInstant); 86 87 return builder() 88 .setAdSelectionId(adSelectionId) 89 .setCreationInstant(creationInstant) 90 .setSeller(seller) 91 .setCallerPackageName(callerPackageName) 92 .build(); 93 } 94 95 /** Builder class for a {@link DBAdSelectionInitialization}. */ 96 @AutoValue.Builder 97 public abstract static class Builder { 98 /** Sets ad selection id. */ setAdSelectionId(long adSelectionId)99 public abstract Builder setAdSelectionId(long adSelectionId); 100 101 /** Sets the creation instant for this ad selection run initialization. */ setCreationInstant(@onNull Instant creationInstant)102 public abstract Builder setCreationInstant(@NonNull Instant creationInstant); 103 104 /** Sets seller ad tech. */ setSeller(@ullable AdTechIdentifier seller)105 public abstract Builder setSeller(@Nullable AdTechIdentifier seller); 106 107 /** Sets the caller package name which initiated this ad selection run. */ setCallerPackageName(@ullable String callerPackageName)108 public abstract Builder setCallerPackageName(@Nullable String callerPackageName); 109 110 /** Builds a {@link DBAdSelectionInitialization} object. */ build()111 public abstract DBAdSelectionInitialization build(); 112 } 113 } 114