1 /*
2  * Copyright (C) 2022 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 androidx.annotation.NonNull;
20 import androidx.room.ColumnInfo;
21 import androidx.room.Entity;
22 import androidx.room.PrimaryKey;
23 
24 import com.google.auto.value.AutoValue;
25 import com.google.auto.value.AutoValue.CopyAnnotations;
26 
27 /** This POJO represents the AdSelectionOverride data in the ad_selection_overrides table entity. */
28 @AutoValue
29 @CopyAnnotations
30 @Entity(tableName = "ad_selection_overrides")
31 public abstract class DBAdSelectionOverride {
32 
33     /**
34      * @return AdSelectionConfigId, the primary key of the ad_selection_overrides table
35      */
36     @CopyAnnotations
37     @ColumnInfo(name = "ad_selection_config_id")
38     @PrimaryKey
39     @NonNull
getAdSelectionConfigId()40     public abstract String getAdSelectionConfigId();
41 
42     /**
43      * @return App package name
44      */
45     @CopyAnnotations
46     @ColumnInfo(name = "app_package_name")
47     @NonNull
getAppPackageName()48     public abstract String getAppPackageName();
49 
50     /**
51      * @return The override javascript result
52      */
53     @CopyAnnotations
54     @ColumnInfo(name = "decision_logic")
55     @NonNull
getDecisionLogicJS()56     public abstract String getDecisionLogicJS();
57 
58     /** @return The override trusted scoring signals */
59     @CopyAnnotations
60     @ColumnInfo(name = "trusted_scoring_signals")
61     @NonNull
getTrustedScoringSignals()62     public abstract String getTrustedScoringSignals();
63 
64     /** @return DBAdSelectionOverride built with those params */
create( String adSelectionConfigId, String appPackageName, String decisionLogicJS, String trustedScoringSignals)65     public static DBAdSelectionOverride create(
66             String adSelectionConfigId,
67             String appPackageName,
68             String decisionLogicJS,
69             String trustedScoringSignals) {
70         return builder()
71                 .setAdSelectionConfigId(adSelectionConfigId)
72                 .setAppPackageName(appPackageName)
73                 .setDecisionLogicJS(decisionLogicJS)
74                 .setTrustedScoringSignals(trustedScoringSignals)
75                 .build();
76     }
77 
78     /**
79      * @return generic builder
80      */
builder()81     public static DBAdSelectionOverride.Builder builder() {
82         return new AutoValue_DBAdSelectionOverride.Builder();
83     }
84 
85     @AutoValue.Builder
86     public abstract static class Builder {
87         /** Sets the ID for the {@link DBAdSelectionOverride} entry. */
setAdSelectionConfigId( String adSelectionConfigId)88         public abstract DBAdSelectionOverride.Builder setAdSelectionConfigId(
89                 String adSelectionConfigId);
90 
91         /** Sets the Package Name of the app creating the override. */
setAppPackageName(String appPackageName)92         public abstract DBAdSelectionOverride.Builder setAppPackageName(String appPackageName);
93 
94         /** Sets the JS code to use instead of fetching it from a trusted server. */
setDecisionLogicJS(String decisionLogicJS)95         public abstract DBAdSelectionOverride.Builder setDecisionLogicJS(String decisionLogicJS);
96 
97         /** Sets the Trusted Scoring Signals to use instead of fetching it from a trusted server. */
setTrustedScoringSignals( String trustedScoringSignals)98         public abstract DBAdSelectionOverride.Builder setTrustedScoringSignals(
99                 String trustedScoringSignals);
100 
101         /**
102          * @return an instance of {@link DBAdSelectionOverride} built with the information in this
103          *     builder.
104          */
build()105         public abstract DBAdSelectionOverride build();
106     }
107 }
108