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 /** 43 * Win reporting uri associated with the component seller. This field will be null if there is 44 * no component seller. 45 */ 46 @Nullable getComponentSellerWinReportingUri()47 public abstract Uri getComponentSellerWinReportingUri(); 48 49 /** The data required for computing the reporting Uris. */ 50 @AutoValue.CopyAnnotations 51 @Nullable 52 @Ignore getReportingComputationData()53 public abstract ReportingComputationData getReportingComputationData(); 54 55 /** 56 * @return generic builder 57 */ builder()58 public static Builder builder() { 59 return new AutoValue_ReportingData.Builder(); 60 } 61 62 /** 63 * Factory method to create ReportingData containing URIs. Room uses this factory method to 64 * create objects. 65 */ createWithUris( @onNull Uri buyerWinReportingUri, @NonNull Uri sellerWinReportingUri, @NonNull Uri componentSellerWinReportingUri)66 public static ReportingData createWithUris( 67 @NonNull Uri buyerWinReportingUri, 68 @NonNull Uri sellerWinReportingUri, 69 @NonNull Uri componentSellerWinReportingUri) { 70 Objects.requireNonNull(buyerWinReportingUri); 71 Objects.requireNonNull(sellerWinReportingUri); 72 73 return builder() 74 .setBuyerWinReportingUri(buyerWinReportingUri) 75 .setSellerWinReportingUri(sellerWinReportingUri) 76 .setComponentSellerWinReportingUri(componentSellerWinReportingUri) 77 .build(); 78 } 79 80 /** Builder for ReportingData. */ 81 @AutoValue.Builder 82 public abstract static class Builder { 83 84 /** Sets the win reporting uri associated with the buyer adtech. */ setBuyerWinReportingUri(@ullable Uri buyerWinReportingUri)85 public abstract Builder setBuyerWinReportingUri(@Nullable Uri buyerWinReportingUri); 86 87 /** Sets the win reporting uri associated with the seller adtech. */ setSellerWinReportingUri(@ullable Uri sellerWinReportingUri)88 public abstract Builder setSellerWinReportingUri(@Nullable Uri sellerWinReportingUri); 89 90 /** Sets the win reporting uri associated with the component seller adtech. */ setComponentSellerWinReportingUri( @ullable Uri componentSellerWinReportingUri)91 public abstract Builder setComponentSellerWinReportingUri( 92 @Nullable Uri componentSellerWinReportingUri); 93 94 /** Sets the data required for computing the reporting Uris. */ setReportingComputationData( @ullable ReportingComputationData reportingComputationData)95 public abstract Builder setReportingComputationData( 96 @Nullable ReportingComputationData reportingComputationData); 97 autoBuild()98 abstract ReportingData autoBuild(); 99 100 /** Builds a {@link ReportingData} object. */ build()101 public ReportingData build() { 102 ReportingData reportingData = autoBuild(); 103 104 boolean reportingUriSet = 105 reportingData.getBuyerWinReportingUri() != null 106 || reportingData.getSellerWinReportingUri() != null 107 || reportingData.getComponentSellerWinReportingUri() != null; 108 boolean reportingComputationDataSet = 109 reportingData.getReportingComputationData() != null; 110 Preconditions.checkArgument( 111 reportingUriSet ^ reportingComputationDataSet, 112 "Both reporting Uris and reporting computation data set " 113 + "to non null values in ReportingData. Only one of those should" 114 + "be set."); 115 return reportingData; 116 } 117 } 118 } 119