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 import android.net.Uri;
22 
23 import androidx.room.ColumnInfo;
24 import androidx.room.Entity;
25 import androidx.room.Index;
26 import androidx.room.PrimaryKey;
27 
28 import com.google.auto.value.AutoValue;
29 
30 import java.time.Instant;
31 import java.util.Objects;
32 
33 /** POJO for the debug reports generated during an ad selection.. */
34 @AutoValue
35 @AutoValue.CopyAnnotations
36 @Entity(
37         tableName = DBAdSelectionDebugReport.TABLE_NAME,
38         indices = {@Index(value = {"creation_timestamp"})})
39 public abstract class DBAdSelectionDebugReport {
40 
41     public static final String TABLE_NAME = "ad_selection_debug_report";
42 
43     /** Gets the autogenerated ad selection debug report id. */
44     @AutoValue.CopyAnnotations
45     @ColumnInfo(name = "ad_selection_debug_report_id")
46     @PrimaryKey(autoGenerate = true)
47     @Nullable
getAdSelectionDebugReportId()48     public abstract Long getAdSelectionDebugReportId();
49 
50     /** Gets the debug report uri. */
51     @AutoValue.CopyAnnotations
52     @ColumnInfo(name = "debug_report_uri")
53     @NonNull
getDebugReportUri()54     public abstract Uri getDebugReportUri();
55 
56     /** Gets the dev options enabled flag. */
57     @AutoValue.CopyAnnotations
58     @ColumnInfo(name = "dev_options_enabled")
59     @NonNull
getDevOptionsEnabled()60     public abstract boolean getDevOptionsEnabled();
61 
62     /** Gets the creation timestamp. */
63     @AutoValue.CopyAnnotations
64     @ColumnInfo(name = "creation_timestamp")
65     @NonNull
getCreationTimestamp()66     public abstract long getCreationTimestamp();
67 
68     /** Returns an AutoValue builder for a {@link DBAdSelectionDebugReport} object. */
69     @NonNull
builder()70     public static Builder builder() {
71         return new AutoValue_DBAdSelectionDebugReport.Builder()
72                 .setAdSelectionDebugReportId(null)
73                 .setCreationTimestamp(Instant.now().toEpochMilli());
74     }
75 
76     /** creates a DBAdSelectionDebugReport object. */
77     @NonNull
create( @ullable Long adSelectionDebugReportId, @NonNull Uri debugReportUri, boolean devOptionsEnabled, long creationTimestamp)78     public static DBAdSelectionDebugReport create(
79             @Nullable Long adSelectionDebugReportId,
80             @NonNull Uri debugReportUri,
81             boolean devOptionsEnabled,
82             long creationTimestamp) {
83         Objects.requireNonNull(debugReportUri);
84         return builder()
85                 .setAdSelectionDebugReportId(adSelectionDebugReportId)
86                 .setDebugReportUri(debugReportUri)
87                 .setDevOptionsEnabled(devOptionsEnabled)
88                 .setCreationTimestamp(creationTimestamp)
89                 .build();
90     }
91 
92     /** Builder class for a {@link DBAdSelectionDebugReport} object. */
93     @AutoValue.Builder
94     public abstract static class Builder {
95         /**
96          * Sets the numerical ID linking {@link DBAdSelectionDebugReport}.d.
97          *
98          * <p>This ID is only used internally and does not need to be stable or reproducible. It is
99          * auto-generated by Room if set to {@code null} on insertion.
100          */
101         @NonNull
setAdSelectionDebugReportId( @ullable Long adSelectionDebugReportId)102         public abstract Builder setAdSelectionDebugReportId(
103                 @Nullable Long adSelectionDebugReportId);
104 
105         /** Sets the debug report Uri. */
106         @NonNull
setDebugReportUri(@onNull Uri debugReportUri)107         public abstract Builder setDebugReportUri(@NonNull Uri debugReportUri);
108 
109         /** Sets if the dev options are enabled. */
110         @NonNull
setDevOptionsEnabled(boolean devOptionsEnabled)111         public abstract Builder setDevOptionsEnabled(boolean devOptionsEnabled);
112 
113         /** Sets the creation timestamp. */
114         @NonNull
setCreationTimestamp(long creationTimestamp)115         public abstract Builder setCreationTimestamp(long creationTimestamp);
116 
117         /**
118          * Builds and returns the {@link DBAdSelectionDebugReport} object.
119          *
120          * @throws IllegalStateException if any required field is unset when the object is built
121          */
122         @NonNull
build()123         public abstract DBAdSelectionDebugReport build();
124     }
125 }
126