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 com.android.adservices.data.customaudience; 18 19 import android.adservices.common.AdTechIdentifier; 20 import android.net.Uri; 21 22 import androidx.annotation.NonNull; 23 import androidx.room.ColumnInfo; 24 import androidx.room.Entity; 25 import androidx.room.ForeignKey; 26 27 import com.google.auto.value.AutoValue; 28 29 /** Represents data specific to a component ad that is necessary for ad selection and rendering. */ 30 @AutoValue 31 @AutoValue.CopyAnnotations 32 @Entity( 33 tableName = DBComponentAdData.TABLE_NAME, 34 foreignKeys = 35 @ForeignKey( 36 entity = DBCustomAudience.class, 37 parentColumns = {"owner", "buyer", "name"}, 38 childColumns = {"owner", "buyer", "name"}, 39 onDelete = ForeignKey.CASCADE), 40 primaryKeys = {"owner", "buyer", "name", "renderUri"}, 41 // Since since we are using {@code AutoValue}, we need to set this parameter to true so that 42 // the generated 43 // class inherits these indices 44 inheritSuperIndices = true) 45 public abstract class DBComponentAdData { 46 public static final String TABLE_NAME = "component_ad_data"; 47 48 /** 49 * @return the owner of the custom audience that this component ad belongs to. 50 */ 51 @AutoValue.CopyAnnotations 52 @ColumnInfo(name = "owner", index = true) 53 @NonNull getOwner()54 public abstract String getOwner(); 55 56 /** 57 * @return the buyer of the custom audience that this component ad belongs to. 58 */ 59 @AutoValue.CopyAnnotations 60 @ColumnInfo(name = "buyer", index = true) 61 @NonNull getBuyer()62 public abstract AdTechIdentifier getBuyer(); 63 64 /** 65 * @return the name of the custom audience that this component ad belongs to. 66 */ 67 @AutoValue.CopyAnnotations 68 @ColumnInfo(name = "name", index = true) 69 @NonNull getName()70 public abstract String getName(); 71 72 /** 73 * @return the render uri associated with this component ad. 74 */ 75 @AutoValue.CopyAnnotations 76 @ColumnInfo(name = "renderUri") 77 @NonNull getRenderUri()78 public abstract Uri getRenderUri(); 79 80 /** 81 * @return the render id associated with this component ad. 82 */ 83 @AutoValue.CopyAnnotations 84 @ColumnInfo(name = "renderId") 85 @NonNull getRenderId()86 public abstract String getRenderId(); 87 88 /** 89 * Creates a {@link DBComponentAdData} object using the builder. 90 * 91 * <p>Required for Room SQLite integration. 92 */ 93 @NonNull create( @onNull String owner, @NonNull AdTechIdentifier buyer, @NonNull String name, @NonNull Uri renderUri, @NonNull String renderId)94 public static DBComponentAdData create( 95 @NonNull String owner, 96 @NonNull AdTechIdentifier buyer, 97 @NonNull String name, 98 @NonNull Uri renderUri, 99 @NonNull String renderId) { 100 return builder() 101 .setOwner(owner) 102 .setBuyer(buyer) 103 .setName(name) 104 .setRenderUri(renderUri) 105 .setRenderId(renderId) 106 .build(); 107 } 108 109 /** Returns an AutoValue builder for a {@link DBComponentAdData} entity. */ 110 @NonNull builder()111 public static DBComponentAdData.Builder builder() { 112 return new AutoValue_DBComponentAdData.Builder(); 113 } 114 115 /** Builder class for a {@link DBCustomAudienceQuarantine}. */ 116 @AutoValue.Builder 117 public abstract static class Builder { 118 /** Sets the owner. */ 119 @NonNull setOwner(@onNull String value)120 public abstract Builder setOwner(@NonNull String value); 121 122 /** Sets the buyer. */ 123 @NonNull setBuyer(@onNull AdTechIdentifier value)124 public abstract Builder setBuyer(@NonNull AdTechIdentifier value); 125 126 /** Sets the name. */ 127 @NonNull setName(@onNull String value)128 public abstract Builder setName(@NonNull String value); 129 130 /** Sets the render uri. */ 131 @NonNull setRenderUri(@onNull Uri value)132 public abstract Builder setRenderUri(@NonNull Uri value); 133 134 /** Sets the render id. */ 135 @NonNull setRenderId(@onNull String value)136 public abstract Builder setRenderId(@NonNull String value); 137 138 /** Builds the {@link DBComponentAdData}. */ 139 @NonNull build()140 public abstract DBComponentAdData build(); 141 } 142 } 143