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.service.adselection;
18 
19 import android.adservices.common.AdData;
20 import android.annotation.NonNull;
21 
22 import com.android.adservices.data.adselection.DBAdSelection;
23 import com.android.adservices.data.common.DBAdData;
24 import com.android.adservices.service.js.JSScriptRecordArgument;
25 
26 import org.json.JSONObject;
27 
28 /**
29  * Interface for persisting the ad counter keys for an ad throughout the ad selection process and
30  * into the ad selection table.
31  */
32 public interface AdCounterKeyCopier {
33     /**
34      * Copies the ad counter keys from the source {@link DBAdData} into the given {@link
35      * AdData.Builder} and returns it.
36      *
37      * <p>Note that the given {@code targetBuilder} will be modified.
38      */
39     @NonNull
copyAdCounterKeys( @onNull AdData.Builder targetBuilder, @NonNull DBAdData sourceAdData)40     AdData.Builder copyAdCounterKeys(
41             @NonNull AdData.Builder targetBuilder, @NonNull DBAdData sourceAdData);
42 
43     /**
44      * Copies the ad counter keys from the source {@link AdData} into a copy of the given {@link
45      * JSScriptRecordArgument} and returns the copy.
46      */
47     @NonNull
copyAdCounterKeys( @onNull JSScriptRecordArgument originalRecordArgument, @NonNull AdData sourceAdData)48     JSScriptRecordArgument copyAdCounterKeys(
49             @NonNull JSScriptRecordArgument originalRecordArgument, @NonNull AdData sourceAdData);
50 
51     /**
52      * Copies the ad counter keys from the source {@link DBAdData} into a copy of the given {@link
53      * JSScriptRecordArgument} and returns the copy.
54      */
55     @NonNull
copyAdCounterKeys( @onNull JSScriptRecordArgument originalRecordArgument, @NonNull DBAdData sourceAdData)56     JSScriptRecordArgument copyAdCounterKeys(
57             @NonNull JSScriptRecordArgument originalRecordArgument, @NonNull DBAdData sourceAdData);
58 
59     /**
60      * Parses the ad counter keys from the JSON bidding or scoring result and copies any keys into
61      * the given {@link AdData.Builder} and returns it.
62      *
63      * <p>Note that the given {@code targetBuilder} will be modified.
64      */
65     @NonNull
copyAdCounterKeys( @onNull AdData.Builder targetBuilder, @NonNull JSONObject sourceObject)66     AdData.Builder copyAdCounterKeys(
67             @NonNull AdData.Builder targetBuilder, @NonNull JSONObject sourceObject);
68 
69     /**
70      * Copies the ad counter keys from the winning ad's {@link AdScoringOutcome} to the given {@link
71      * DBAdSelection.Builder} which will be persisted into the ad selection table and returns it.
72      *
73      * <p>Note that the given {@code targetBuilder} will be modified.
74      */
75     @NonNull
copyAdCounterKeys( @onNull DBAdSelection.Builder targetBuilder, @NonNull AdScoringOutcome sourceOutcome)76     DBAdSelection.Builder copyAdCounterKeys(
77             @NonNull DBAdSelection.Builder targetBuilder, @NonNull AdScoringOutcome sourceOutcome);
78 }
79