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 
26 /**
27  * This POJO represents the AdSelectionFromOutcomesOverride data in the ad_selection_overrides table
28  * entity.
29  */
30 @AutoValue
31 @AutoValue.CopyAnnotations
32 @Entity(tableName = "ad_selection_from_outcomes_overrides")
33 public abstract class DBAdSelectionFromOutcomesOverride {
34     /**
35      * @return AdSelectionFromOutcomesConfigId, the primary key of the
36      *     ad_selection_from_outcomes_overrides table
37      */
38     @AutoValue.CopyAnnotations
39     @ColumnInfo(name = "ad_selection_from_outcomes_config_id")
40     @PrimaryKey
41     @NonNull
getAdSelectionFromOutcomesConfigId()42     public abstract String getAdSelectionFromOutcomesConfigId();
43 
44     /** @return App package name */
45     @AutoValue.CopyAnnotations
46     @ColumnInfo(name = "app_package_name")
47     @NonNull
getAppPackageName()48     public abstract String getAppPackageName();
49 
50     /**
51      * @return The override javascript result to use for outcome selection in {@link
52      *     com.android.adservices.service.adselection.AdOutcomeSelectorImpl}
53      */
54     @AutoValue.CopyAnnotations
55     @ColumnInfo(name = "selection_logic_js")
56     @NonNull
getSelectionLogicJs()57     public abstract String getSelectionLogicJs();
58 
59     /** @return The override selection signals */
60     @AutoValue.CopyAnnotations
61     @ColumnInfo(name = "selection_signals")
62     @NonNull
getSelectionSignals()63     public abstract String getSelectionSignals();
64 
65     /** @return {@link DBAdSelectionFromOutcomesOverride } built with those params */
create( String adSelectionFromOutcomesConfigId, String appPackageName, String selectionLogicJs, String selectionSignals)66     public static DBAdSelectionFromOutcomesOverride create(
67             String adSelectionFromOutcomesConfigId,
68             String appPackageName,
69             String selectionLogicJs,
70             String selectionSignals) {
71         return builder()
72                 .setAdSelectionFromOutcomesConfigId(adSelectionFromOutcomesConfigId)
73                 .setAppPackageName(appPackageName)
74                 .setSelectionLogicJs(selectionLogicJs)
75                 .setSelectionSignals(selectionSignals)
76                 .build();
77     }
78 
79     /** @return generic builder */
builder()80     public static DBAdSelectionFromOutcomesOverride.Builder builder() {
81         return new AutoValue_DBAdSelectionFromOutcomesOverride.Builder();
82     }
83 
84     /** @return generic builder */
85     @AutoValue.Builder
86     public abstract static class Builder {
87         /** Sets the ID for the {@link DBAdSelectionFromOutcomesOverride} entry. */
88         public abstract DBAdSelectionFromOutcomesOverride.Builder
setAdSelectionFromOutcomesConfigId(String adSelectionFromOutcomesConfigId)89                 setAdSelectionFromOutcomesConfigId(String adSelectionFromOutcomesConfigId);
90 
91         /** Sets the Package Name of the app creating the override. */
setAppPackageName( String appPackageName)92         public abstract DBAdSelectionFromOutcomesOverride.Builder setAppPackageName(
93                 String appPackageName);
94 
95         /** Sets the JS code to use instead of fetching it from a trusted server. */
setSelectionLogicJs( String selectionLogicJs)96         public abstract DBAdSelectionFromOutcomesOverride.Builder setSelectionLogicJs(
97                 String selectionLogicJs);
98 
99         /** Sets the Trusted Scoring Signals to use instead of fetching it from a trusted server. */
setSelectionSignals( String selectionSignals)100         public abstract DBAdSelectionFromOutcomesOverride.Builder setSelectionSignals(
101                 String selectionSignals);
102 
103         /**
104          * @return an instance of {@link DBAdSelectionFromOutcomesOverride} built with the
105          *     information in this builder.
106          */
build()107         public abstract DBAdSelectionFromOutcomesOverride build();
108     }
109 }
110