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.signals; 18 19 import android.adservices.common.AdTechIdentifier; 20 21 import androidx.annotation.NonNull; 22 import androidx.annotation.Nullable; 23 import androidx.room.ColumnInfo; 24 import androidx.room.Entity; 25 import androidx.room.PrimaryKey; 26 27 import com.android.adservices.service.signals.evict.EvictionPriority; 28 29 import com.google.auto.value.AutoValue; 30 31 import java.time.Instant; 32 33 /** POJO representing a Protected Signal. */ 34 @AutoValue 35 @AutoValue.CopyAnnotations 36 @Entity(tableName = DBProtectedSignal.TABLE_NAME, inheritSuperIndices = true) 37 public abstract class DBProtectedSignal { 38 public static final String TABLE_NAME = "protected_signals"; 39 40 /** The id of the signal. Should be left null to be auto-populated by Room. */ 41 @AutoValue.CopyAnnotations 42 @ColumnInfo(name = "id") 43 @PrimaryKey(autoGenerate = true) 44 @Nullable getId()45 public abstract Long getId(); 46 47 /** The adtech buyer who created/will use the signal. */ 48 @AutoValue.CopyAnnotations 49 @ColumnInfo(name = "buyer", index = true) 50 @NonNull getBuyer()51 public abstract AdTechIdentifier getBuyer(); 52 53 /** The bytes of the signal's key. */ 54 @AutoValue.CopyAnnotations 55 @ColumnInfo(name = "key") 56 @NonNull getKey()57 public abstract byte[] getKey(); 58 59 /** The bytes of the signal's value. */ 60 @AutoValue.CopyAnnotations 61 @ColumnInfo(name = "value") 62 @NonNull getValue()63 public abstract byte[] getValue(); 64 65 /** The time the signal was created (truncated to milliseconds). */ 66 @AutoValue.CopyAnnotations 67 @ColumnInfo(name = "creationTime") 68 @NonNull getCreationTime()69 public abstract Instant getCreationTime(); 70 71 /** The package that created the signal. */ 72 @AutoValue.CopyAnnotations 73 @ColumnInfo(name = "packageName") 74 @NonNull getPackageName()75 public abstract String getPackageName(); 76 77 /** The eviction priority of the signal. */ 78 @AutoValue.CopyAnnotations 79 @ColumnInfo(name = "evictionPriority", defaultValue = "0") getEvictionPriority()80 public abstract EvictionPriority getEvictionPriority(); 81 82 /** 83 * @return The builder for this object. 84 */ 85 @NonNull builder()86 public static DBProtectedSignal.Builder builder() { 87 return new AutoValue_DBProtectedSignal.Builder() 88 .setId(null) 89 .setEvictionPriority(EvictionPriority.DEFAULT); 90 } 91 92 /** Creates a DBProtectedSignal. Required by Room for AutoValue classes. */ 93 @NonNull create( @ullable Long id, @NonNull AdTechIdentifier buyer, @NonNull byte[] key, @NonNull byte[] value, @NonNull Instant creationTime, @NonNull String packageName, EvictionPriority evictionPriority)94 public static DBProtectedSignal create( 95 @Nullable Long id, 96 @NonNull AdTechIdentifier buyer, 97 @NonNull byte[] key, 98 @NonNull byte[] value, 99 @NonNull Instant creationTime, 100 @NonNull String packageName, 101 EvictionPriority evictionPriority) { 102 return builder() 103 .setId(id) 104 .setBuyer(buyer) 105 .setKey(key) 106 .setValue(value) 107 .setCreationTime(creationTime) 108 .setPackageName(packageName) 109 .setEvictionPriority(evictionPriority) 110 .build(); 111 } 112 113 @AutoValue.Builder 114 public abstract static class Builder { 115 /** For more details see {@link #getId()} */ setId(Long id)116 public abstract Builder setId(Long id); 117 118 /** For more details see {@link #getBuyer()} */ 119 @NonNull setBuyer(@onNull AdTechIdentifier buyer)120 public abstract Builder setBuyer(@NonNull AdTechIdentifier buyer); 121 122 /** For more details see {@link #getKey()} */ 123 @NonNull setKey(@onNull byte[] key)124 public abstract Builder setKey(@NonNull byte[] key); 125 126 /** For more details see {@link #getValue()} */ 127 @NonNull setValue(@onNull byte[] value)128 public abstract Builder setValue(@NonNull byte[] value); 129 130 /** For more details see {@link #getCreationTime()} */ setCreationTime(@onNull Instant creationTime)131 public abstract Builder setCreationTime(@NonNull Instant creationTime); 132 133 /** For more details see {@link #getPackageName()} */ 134 @NonNull setPackageName(@onNull String packageName)135 public abstract Builder setPackageName(@NonNull String packageName); 136 137 /** For more details see {@link #getEvictionPriority()} */ 138 @NonNull setEvictionPriority(@onNull EvictionPriority evictionPriority)139 public abstract Builder setEvictionPriority(@NonNull EvictionPriority evictionPriority); 140 141 /** 142 * @return an instance of {@link DBProtectedSignal} 143 */ 144 @NonNull build()145 public abstract DBProtectedSignal build(); 146 } 147 } 148