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