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.datahandlers;
18 
19 import android.annotation.NonNull;
20 
21 import androidx.annotation.Nullable;
22 
23 import com.google.auto.value.AutoValue;
24 
25 import java.util.Set;
26 
27 /** Data class representing the custom audience which won an ad selection run . */
28 @AutoValue
29 public abstract class WinningCustomAudience {
30 
31     /** Winner custom audience owner name, i.e. the caller package which created the CA. */
32     @Nullable
getOwner()33     public abstract String getOwner();
34 
35     /** Winner custom audience name. */
36     @NonNull
getName()37     public abstract String getName();
38 
39     /** Ad counter keys associated with the winning custom audience ad. */
40     @Nullable
getAdCounterKeys()41     public abstract Set<Integer> getAdCounterKeys();
42 
43     /**
44      * Creates a {@link WinningCustomAudience} object using the builder.
45      *
46      * <p>Required for Room SQLite integration.
47      */
48     @NonNull
create( @ullable String owner, String name, @Nullable Set<Integer> adCounterKeys)49     public static WinningCustomAudience create(
50             @Nullable String owner, String name, @Nullable Set<Integer> adCounterKeys) {
51         return builder().setOwner(owner).setName(name).setAdCounterKeys(adCounterKeys).build();
52     }
53 
54     /**
55      * @return generic builder
56      */
57     @NonNull
builder()58     public static Builder builder() {
59         return new AutoValue_WinningCustomAudience.Builder();
60     }
61 
62     /** Builder for WinningCustomAudience. */
63     @AutoValue.Builder
64     public abstract static class Builder {
65 
66         /** Winner custom audience owner name, i.e. the caller package which created the CA. */
setOwner(@ullable String owner)67         public abstract Builder setOwner(@Nullable String owner);
68 
69         /** Sets the winner custom audience name. */
setName(@onNull String name)70         public abstract Builder setName(@NonNull String name);
71 
72         /** Sets the ad counter keys associated with the winning custom audience ad. */
setAdCounterKeys(@ullable Set<Integer> adCounterKeys)73         public abstract Builder setAdCounterKeys(@Nullable Set<Integer> adCounterKeys);
74 
75         /** Builds a {@link WinningCustomAudience} object. */
76         @NonNull
build()77         public abstract WinningCustomAudience build();
78     }
79 }
80