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 import android.annotation.Nullable;
21 import android.net.Uri;
22 
23 import androidx.room.Ignore;
24 
25 import com.google.auto.value.AutoValue;
26 import com.google.common.base.Preconditions;
27 
28 import java.util.Objects;
29 
30 /** Data class representing the event level reporting data associated with an ad selection run. */
31 @AutoValue
32 public abstract class ReportingData {
33 
34     /** Win reporting uri associated with the buyer adtech. */
35     @Nullable
getBuyerWinReportingUri()36     public abstract Uri getBuyerWinReportingUri();
37 
38     /** Win reporting uri associated with the seller adtech. */
39     @Nullable
getSellerWinReportingUri()40     public abstract Uri getSellerWinReportingUri();
41 
42     /** The data required for computing the reporting Uris. */
43     @AutoValue.CopyAnnotations
44     @Nullable
45     @Ignore
getReportingComputationData()46     public abstract ReportingComputationData getReportingComputationData();
47 
48     /**
49      * @return generic builder
50      */
builder()51     public static Builder builder() {
52         return new AutoValue_ReportingData.Builder();
53     }
54 
55     /**
56      * Factory method to create ReportingData containing URIs. Room uses this factory method to
57      * create objects.
58      */
createWithUris( @onNull Uri buyerWinReportingUri, @NonNull Uri sellerWinReportingUri)59     public static ReportingData createWithUris(
60             @NonNull Uri buyerWinReportingUri, @NonNull Uri sellerWinReportingUri) {
61         Objects.requireNonNull(buyerWinReportingUri);
62         Objects.requireNonNull(sellerWinReportingUri);
63 
64         return builder()
65                 .setBuyerWinReportingUri(buyerWinReportingUri)
66                 .setSellerWinReportingUri(sellerWinReportingUri)
67                 .build();
68     }
69 
70     /** Builder for ReportingData. */
71     @AutoValue.Builder
72     public abstract static class Builder {
73 
74         /** Sets the win reporting uri associated with the buyer adtech. */
setBuyerWinReportingUri(@ullable Uri buyerWinReportingUri)75         public abstract Builder setBuyerWinReportingUri(@Nullable Uri buyerWinReportingUri);
76 
77         /** Sets the win reporting uri associated with the seller adtech. */
setSellerWinReportingUri(@ullable Uri sellerWinReportingUri)78         public abstract Builder setSellerWinReportingUri(@Nullable Uri sellerWinReportingUri);
79 
80         /** Sets the data required for computing the reporting Uris. */
setReportingComputationData( @ullable ReportingComputationData reportingComputationData)81         public abstract Builder setReportingComputationData(
82                 @Nullable ReportingComputationData reportingComputationData);
83 
autoBuild()84         abstract ReportingData autoBuild();
85 
86         /** Builds a {@link ReportingData} object. */
build()87         public ReportingData build() {
88             ReportingData reportingData = autoBuild();
89 
90             boolean reportingUriSet =
91                     reportingData.getBuyerWinReportingUri() != null
92                             || reportingData.getSellerWinReportingUri() != null;
93             boolean reportingComputationDataSet =
94                     reportingData.getReportingComputationData() != null;
95             Preconditions.checkArgument(
96                     reportingUriSet ^ reportingComputationDataSet,
97                     "Both reporting Uris and reporting computation data set "
98                             + "to non null values in ReportingData. Only one of those should"
99                             + "be set.");
100             return reportingData;
101         }
102     }
103 }
104