1 /* 2 * Copyright (C) 2024 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.annotation.NonNull; 20 import android.annotation.Nullable; 21 22 import androidx.room.ColumnInfo; 23 import androidx.room.Entity; 24 import androidx.room.Index; 25 import androidx.room.PrimaryKey; 26 27 import com.google.auto.value.AutoValue; 28 29 import java.time.Instant; 30 import java.util.Objects; 31 32 @AutoValue 33 @AutoValue.CopyAnnotations 34 @Entity( 35 tableName = DBConsentedDebugConfiguration.TABLE_NAME, 36 indices = {@Index(value = {"creation_timestamp"})}) 37 public abstract class DBConsentedDebugConfiguration { 38 public static final String TABLE_NAME = "consented_debug_configuration"; 39 40 /** Gets the autogenerated ad selection debug report id. */ 41 @AutoValue.CopyAnnotations 42 @ColumnInfo(name = "consented_debug_configuration_primary_key") 43 @PrimaryKey(autoGenerate = true) 44 @Nullable getConsentedDebugConfigurationPrimaryKey()45 public abstract Long getConsentedDebugConfigurationPrimaryKey(); 46 47 /** Gets the debug report uri. */ 48 @AutoValue.CopyAnnotations 49 @ColumnInfo(name = "is_consent_provided") 50 @NonNull getIsConsentProvided()51 public abstract boolean getIsConsentProvided(); 52 53 /** Gets the dev options enabled flag. */ 54 @AutoValue.CopyAnnotations 55 @ColumnInfo(name = "debug_token") 56 @NonNull getDebugToken()57 public abstract String getDebugToken(); 58 59 /** Gets the creation timestamp. */ 60 @AutoValue.CopyAnnotations 61 @ColumnInfo(name = "creation_timestamp") 62 @NonNull getCreationTimestamp()63 public abstract Instant getCreationTimestamp(); 64 65 /** Gets the creation timestamp. */ 66 @AutoValue.CopyAnnotations 67 @ColumnInfo(name = "expiry_timestamp") 68 @NonNull getExpiryTimestamp()69 public abstract Instant getExpiryTimestamp(); 70 71 /** Returns an AutoValue builder for a {@link DBAdSelectionDebugReport} object. */ 72 @NonNull builder()73 public static DBConsentedDebugConfiguration.Builder builder() { 74 return new AutoValue_DBConsentedDebugConfiguration.Builder() 75 .setConsentedDebugConfigurationPrimaryKey(null) 76 .setCreationTimestamp(Instant.now()); 77 } 78 79 /** creates a DBAdSelectionDebugReport object. */ 80 @NonNull create( @ullable Long consentedDebugConfigurationPrimaryKey, boolean isConsentProvided, @NonNull String debugToken, @NonNull Instant creationTimestamp, @NonNull Instant expiryTimestamp)81 public static DBConsentedDebugConfiguration create( 82 @Nullable Long consentedDebugConfigurationPrimaryKey, 83 boolean isConsentProvided, 84 @NonNull String debugToken, 85 @NonNull Instant creationTimestamp, 86 @NonNull Instant expiryTimestamp) { 87 Objects.requireNonNull(debugToken); 88 Objects.requireNonNull(creationTimestamp); 89 Objects.requireNonNull(expiryTimestamp); 90 91 return builder() 92 .setConsentedDebugConfigurationPrimaryKey(consentedDebugConfigurationPrimaryKey) 93 .setIsConsentProvided(isConsentProvided) 94 .setDebugToken(debugToken) 95 .setCreationTimestamp(creationTimestamp) 96 .setExpiryTimestamp(expiryTimestamp) 97 .build(); 98 } 99 100 /** Builder class for a {@link DBConsentedDebugConfiguration} object. */ 101 @AutoValue.Builder 102 public abstract static class Builder { 103 /** 104 * Sets the numerical ID linking {@link DBConsentedDebugConfiguration}.d. 105 * 106 * <p>This primary key is only used internally and does not need to be stable or 107 * reproducible. It is auto-generated by Room if set to {@code null} on insertion. 108 */ 109 @NonNull setConsentedDebugConfigurationPrimaryKey( @ullable Long consentedDebugConfigurationPrimaryKey)110 public abstract Builder setConsentedDebugConfigurationPrimaryKey( 111 @Nullable Long consentedDebugConfigurationPrimaryKey); 112 113 /** Sets is consented provided. */ 114 @NonNull setIsConsentProvided(boolean isConsentProvided)115 public abstract Builder setIsConsentProvided(boolean isConsentProvided); 116 117 /** Sets the debug token. */ 118 @NonNull setDebugToken(@onNull String debugToken)119 public abstract Builder setDebugToken(@NonNull String debugToken); 120 121 /** Sets the creation timestamp. */ 122 @NonNull setCreationTimestamp(@onNull Instant creationTimestamp)123 public abstract Builder setCreationTimestamp(@NonNull Instant creationTimestamp); 124 125 /** Sets the expiry timestamp. */ 126 @NonNull setExpiryTimestamp(@onNull Instant expiryTimestamp)127 public abstract Builder setExpiryTimestamp(@NonNull Instant expiryTimestamp); 128 129 /** 130 * Builds and returns the {@link DBConsentedDebugConfiguration} object. 131 * 132 * @throws IllegalStateException if any required field is unset when the object is built 133 */ 134 @NonNull build()135 public abstract DBConsentedDebugConfiguration build(); 136 } 137 } 138