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.adselection;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 
22 import androidx.room.ColumnInfo;
23 
24 import com.google.auto.value.AutoValue;
25 
26 import java.util.Set;
27 
28 /**
29  * This class represents the data related to a custom audience which has won an ad selection run.
30  */
31 @AutoValue
32 public abstract class DBWinningCustomAudience {
33 
34     /** Name of the winning custom audience. */
35     @AutoValue.CopyAnnotations
36     @ColumnInfo(name = "name")
37     @Nullable
getName()38     public abstract String getName();
39 
40     /** Owner of the winning custom audience, i.e. the caller package name */
41     @AutoValue.CopyAnnotations
42     @Nullable
43     @ColumnInfo(name = "owner")
getOwner()44     public abstract String getOwner();
45 
46     /** Ad counter keys for the winning ad in the winning custom audience. */
47     @AutoValue.CopyAnnotations
48     @Nullable
49     @ColumnInfo(name = "ad_counter_int_keys")
getAdCounterIntKeys()50     public abstract Set<Integer> getAdCounterIntKeys();
51 
52     /** Builder for {@link DBWinningCustomAudience} */
53     @NonNull
builder()54     public static Builder builder() {
55         return new AutoValue_DBWinningCustomAudience.Builder();
56     }
57 
58     /**
59      * Creates a {@link DBWinningCustomAudience} object using the builder.
60      *
61      * <p>Required for Room SQLite integration.
62      */
63     @NonNull
create( @ullable String name, @Nullable String owner, @Nullable Set<Integer> adCounterIntKeys)64     public static DBWinningCustomAudience create(
65             @Nullable String name,
66             @Nullable String owner,
67             @Nullable Set<Integer> adCounterIntKeys) {
68         return builder()
69                 .setName(name)
70                 .setOwner(owner)
71                 .setAdCounterIntKeys(adCounterIntKeys)
72                 .build();
73     }
74 
75     /** Builder class for a {@link DBWinningCustomAudience}. */
76     @AutoValue.Builder
77     public abstract static class Builder {
78         /** Sets the name of the winning custom audience. */
setName(@ullable String name)79         public abstract Builder setName(@Nullable String name);
80 
81         /** Sets the owner of the winning custom audience, i.e. the caller package name */
setOwner(@ullable String owner)82         public abstract Builder setOwner(@Nullable String owner);
83 
84         /** Sets the ad counter keys for the winning ad in the winning custom audience. */
setAdCounterIntKeys(@ullable Set<Integer> adCounterIntKeys)85         public abstract Builder setAdCounterIntKeys(@Nullable Set<Integer> adCounterIntKeys);
86 
87         /** Builds a {@link DBWinningCustomAudience} object. */
build()88         public abstract DBWinningCustomAudience build();
89     }
90 }
91