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.signals;
18 
19 import android.adservices.common.AdTechIdentifier;
20 
21 import androidx.annotation.NonNull;
22 import androidx.room.ColumnInfo;
23 import androidx.room.Entity;
24 import androidx.room.PrimaryKey;
25 
26 import com.google.auto.value.AutoValue;
27 
28 import java.time.Instant;
29 
30 /** Represents an entry for encoded payload for a buyer. */
31 @AutoValue
32 @AutoValue.CopyAnnotations
33 @Entity(tableName = DBEncodedPayload.TABLE_NAME, inheritSuperIndices = true)
34 public abstract class DBEncodedPayload {
35 
36     public static final String TABLE_NAME = "encoded_payload";
37 
38     /** The ad-tech buyer associated with the signals that would be encoded */
39     @AutoValue.CopyAnnotations
40     @ColumnInfo(name = "buyer")
41     @PrimaryKey
42     @NonNull
getBuyer()43     public abstract AdTechIdentifier getBuyer();
44 
45     /** The version provided by Ad tech corresponding for their encoder */
46     @AutoValue.CopyAnnotations
47     @ColumnInfo(name = "version")
getVersion()48     public abstract int getVersion();
49 
50     /** The time at which this entry for encoded payload was persisted */
51     @AutoValue.CopyAnnotations
52     @ColumnInfo(name = "creation_time", index = true)
53     @NonNull
getCreationTime()54     public abstract Instant getCreationTime();
55 
56     /** The encoded payload generated using raw signals and encoder provided by buyer */
57     @AutoValue.CopyAnnotations
58     @ColumnInfo(name = "encoded_payload", typeAffinity = ColumnInfo.BLOB)
59     @NonNull
getEncodedPayload()60     public abstract byte[] getEncodedPayload();
61 
62     /**
63      * @return an instance of {@link DBEncodedPayload}
64      */
create( @onNull AdTechIdentifier buyer, int version, @NonNull Instant creationTime, @NonNull byte[] encodedPayload)65     public static DBEncodedPayload create(
66             @NonNull AdTechIdentifier buyer,
67             int version,
68             @NonNull Instant creationTime,
69             @NonNull byte[] encodedPayload) {
70         return builder()
71                 .setBuyer(buyer)
72                 .setVersion(version)
73                 .setCreationTime(creationTime)
74                 .setEncodedPayload(encodedPayload)
75                 .build();
76     }
77 
78     /**
79      * @return a builder for creating a {@link DBEncodedPayload}
80      */
builder()81     public static DBEncodedPayload.Builder builder() {
82         return new AutoValue_DBEncodedPayload.Builder();
83     }
84 
85     /** Provides a builder to create an instance of {@link DBEncodedPayload} */
86     @AutoValue.Builder
87     public abstract static class Builder {
88 
89         /** For more details see {@link #getBuyer()} */
setBuyer(@onNull AdTechIdentifier value)90         public abstract Builder setBuyer(@NonNull AdTechIdentifier value);
91 
92         /** For more details see {@link #getVersion()} */
setVersion(int value)93         public abstract Builder setVersion(int value);
94 
95         /** For more details see {@link #getCreationTime()} */
setCreationTime(@onNull Instant value)96         public abstract Builder setCreationTime(@NonNull Instant value);
97 
98         /** For more details see {@link #getEncodedPayload()} */
setEncodedPayload(byte[] value)99         public abstract Builder setEncodedPayload(byte[] value);
100 
101         /**
102          * @return an instance of {@link DBEncodedPayload}
103          */
build()104         public abstract DBEncodedPayload build();
105     }
106 }
107