• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package android.adservices.topics;
17 
18 import static android.adservices.topics.TopicsManager.EMPTY_SDK;
19 import static android.adservices.topics.TopicsManager.RECORD_OBSERVATION_DEFAULT;
20 
21 import android.annotation.NonNull;
22 
23 /** Get Topics Request. */
24 public final class GetTopicsRequest {
25 
26     /** Name of Ads SDK that is involved in this request. */
27     private final String mAdsSdkName;
28 
29     /** Whether to record that the caller has observed the topics of the host app or not. */
30     private final boolean mRecordObservation;
31 
GetTopicsRequest(@onNull Builder builder)32     private GetTopicsRequest(@NonNull Builder builder) {
33         mAdsSdkName = builder.mAdsSdkName;
34         mRecordObservation = builder.mRecordObservation;
35     }
36 
37     /** Get the Sdk Name. */
38     @NonNull
getAdsSdkName()39     public String getAdsSdkName() {
40         return mAdsSdkName;
41     }
42 
43     /** Get Record Observation. */
shouldRecordObservation()44     public boolean shouldRecordObservation() {
45         return mRecordObservation;
46     }
47 
48     /** Builder for {@link GetTopicsRequest} objects. */
49     public static final class Builder {
50         private String mAdsSdkName = EMPTY_SDK;
51         private boolean mRecordObservation = RECORD_OBSERVATION_DEFAULT;
52 
53         /** Creates a {@link Builder} for {@link GetTopicsRequest} objects. */
Builder()54         public Builder() {}
55 
56         /**
57          * Set Ads Sdk Name.
58          *
59          * <p>This must be called by SDKs running outside of the Sandbox. Other clients must not
60          * call it.
61          *
62          * @param adsSdkName the Ads Sdk Name.
63          */
64         @NonNull
setAdsSdkName(@onNull String adsSdkName)65         public Builder setAdsSdkName(@NonNull String adsSdkName) {
66             // This is the case the SDK calling from outside of the Sandbox.
67             // Check if the caller set the adsSdkName
68             if (adsSdkName == null) {
69                 throw new IllegalArgumentException(
70                         "When calling Topics API outside of the Sandbox, caller should set Ads Sdk"
71                                 + " Name");
72             }
73 
74             mAdsSdkName = adsSdkName;
75             return this;
76         }
77 
78         /**
79          * Set the Record Observation.
80          *
81          * @param recordObservation whether to record that the caller has observed the topics of the
82          *     host app or not. This will be used to determine if the caller can receive the topic
83          *     in the next epoch.
84          */
85         @NonNull
setShouldRecordObservation(boolean recordObservation)86         public Builder setShouldRecordObservation(boolean recordObservation) {
87             mRecordObservation = recordObservation;
88             return this;
89         }
90 
91         /** Builds a {@link GetTopicsRequest} instance. */
92         @NonNull
build()93         public GetTopicsRequest build() {
94             return new GetTopicsRequest(this);
95         }
96     }
97 }
98