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 android.adservices.adselection;
18 
19 import static android.adservices.adselection.AdSelectionOutcome.UNSET_AD_SELECTION_ID;
20 import static android.adservices.adselection.AdSelectionOutcome.UNSET_AD_SELECTION_ID_MESSAGE;
21 
22 import android.annotation.NonNull;
23 import android.os.OutcomeReceiver;
24 
25 import com.android.internal.util.Preconditions;
26 
27 import java.util.Objects;
28 import java.util.concurrent.Executor;
29 
30 /**
31  * Represent input parameters to the reportImpression API.
32  */
33 public class ReportImpressionRequest {
34     private final long mAdSelectionId;
35     @NonNull private final AdSelectionConfig mAdSelectionConfig;
36 
37     /**
38      * Ctor for on-device ad selection reporting request.
39      *
40      * <p>If your {@code adSelectionId} is for a on-device auction run using {@link
41      * AdSelectionManager#selectAds(AdSelectionConfig, Executor, OutcomeReceiver)} then your
42      * impression reporting request must include your {@link AdSelectionConfig}.
43      *
44      * @param adSelectionId received from {@link AdSelectionManager#selectAds(AdSelectionConfig,
45      *     Executor, OutcomeReceiver)}
46      * @param adSelectionConfig same {@link AdSelectionConfig} used to trigger {@link
47      *     AdSelectionManager#selectAds(AdSelectionConfig, Executor, OutcomeReceiver)}
48      */
ReportImpressionRequest( long adSelectionId, @NonNull AdSelectionConfig adSelectionConfig)49     public ReportImpressionRequest(
50             long adSelectionId, @NonNull AdSelectionConfig adSelectionConfig) {
51         Objects.requireNonNull(adSelectionConfig);
52         Preconditions.checkArgument(
53                 adSelectionId != UNSET_AD_SELECTION_ID, UNSET_AD_SELECTION_ID_MESSAGE);
54 
55         mAdSelectionId = adSelectionId;
56         mAdSelectionConfig = adSelectionConfig;
57     }
58 
59     /**
60      * Ctor for auction server ad selection reporting request.
61      *
62      * <p>If your {@code adSelectionId} is for a server auction run where device info collected by
63      * {@link AdSelectionManager#getAdSelectionData} then your impression reporting request should
64      * only include the ad selection id.
65      *
66      * <p>{@link AdSelectionManager#persistAdSelectionResult} must be called with the encrypted
67      * result blob from servers before making impression reporting request.
68      *
69      * @param adSelectionId received from {@link AdSelectionManager#getAdSelectionData}
70      */
ReportImpressionRequest(long adSelectionId)71     public ReportImpressionRequest(long adSelectionId) {
72         Preconditions.checkArgument(
73                 adSelectionId != UNSET_AD_SELECTION_ID, UNSET_AD_SELECTION_ID_MESSAGE);
74 
75         mAdSelectionId = adSelectionId;
76         mAdSelectionConfig = AdSelectionConfig.EMPTY;
77     }
78 
79     /** Returns the adSelectionId, one of the inputs to {@link ReportImpressionRequest} */
getAdSelectionId()80     public long getAdSelectionId() {
81         return mAdSelectionId;
82     }
83 
84     /** Returns the adSelectionConfig, one of the inputs to {@link ReportImpressionRequest} */
85     @NonNull
getAdSelectionConfig()86     public AdSelectionConfig getAdSelectionConfig() {
87         return mAdSelectionConfig;
88     }
89 }
90