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.customaudience; 18 19 import android.adservices.common.AdTechIdentifier; 20 import android.adservices.customaudience.FetchAndJoinCustomAudienceRequest; 21 import android.os.OutcomeReceiver; 22 23 import androidx.annotation.NonNull; 24 import androidx.room.ColumnInfo; 25 import androidx.room.Entity; 26 import androidx.room.Index; 27 28 import com.google.auto.value.AutoValue; 29 30 import java.time.Instant; 31 import java.util.concurrent.Executor; 32 33 /** 34 * Table containing owner + buyer pairings that are quarantined from calling {@link 35 * android.adservices.customaudience.CustomAudienceManager#fetchAndJoinCustomAudience(FetchAndJoinCustomAudienceRequest, 36 * Executor, OutcomeReceiver)} 37 */ 38 @AutoValue 39 @AutoValue.CopyAnnotations 40 @Entity( 41 tableName = "custom_audience_quarantine", 42 indices = {@Index(value = {"owner", "buyer"})}, 43 primaryKeys = {"owner", "buyer"}) 44 public abstract class DBCustomAudienceQuarantine { 45 /** 46 * @return the owner 47 */ 48 @AutoValue.CopyAnnotations 49 @NonNull 50 @ColumnInfo(name = "owner") getOwner()51 public abstract String getOwner(); 52 53 /** 54 * @return the buyer 55 */ 56 @AutoValue.CopyAnnotations 57 @NonNull 58 @ColumnInfo(name = "buyer") getBuyer()59 public abstract AdTechIdentifier getBuyer(); 60 61 /** 62 * @return the expiration time of the quarantine 63 */ 64 @AutoValue.CopyAnnotations 65 @NonNull 66 @ColumnInfo(name = "quarantine_expiration_time") getQuarantineExpirationTime()67 public abstract Instant getQuarantineExpirationTime(); 68 69 /** 70 * Creates a {@link DBCustomAudienceQuarantine} object using the builder. 71 * 72 * <p>Required for Room SQLite integration. 73 */ 74 @NonNull create( @onNull String owner, @NonNull AdTechIdentifier buyer, @NonNull Instant quarantineExpirationTime)75 public static DBCustomAudienceQuarantine create( 76 @NonNull String owner, 77 @NonNull AdTechIdentifier buyer, 78 @NonNull Instant quarantineExpirationTime) { 79 return builder() 80 .setOwner(owner) 81 .setBuyer(buyer) 82 .setQuarantineExpirationTime(quarantineExpirationTime) 83 .build(); 84 } 85 86 /** Returns an AutoValue builder for a {@link DBCustomAudienceQuarantine} entity. */ 87 @NonNull builder()88 public static DBCustomAudienceQuarantine.Builder builder() { 89 return new AutoValue_DBCustomAudienceQuarantine.Builder(); 90 } 91 92 /** Builder class for a {@link DBCustomAudienceQuarantine}. */ 93 @AutoValue.Builder 94 public abstract static class Builder { 95 /** Sets the owner */ 96 @NonNull setOwner(@onNull String value)97 public abstract Builder setOwner(@NonNull String value); 98 99 /** Sets the buyer */ 100 @NonNull setBuyer(@onNull AdTechIdentifier value)101 public abstract Builder setBuyer(@NonNull AdTechIdentifier value); 102 103 /** 104 * @return Sets the expiration time of the quarantine 105 */ 106 @NonNull setQuarantineExpirationTime(@onNull Instant value)107 public abstract Builder setQuarantineExpirationTime(@NonNull Instant value); 108 109 /** Builds the {@link DBCustomAudienceQuarantine}. */ 110 @NonNull build()111 public abstract DBCustomAudienceQuarantine build(); 112 } 113 } 114