summaryrefslogtreecommitdiff
path: root/adservices/framework/java/android/adservices/topics/GetTopicsRequest.java
blob: cc8e51bdf6aa326efee9106e1ed9bff06a252a75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.adservices.topics;

import static android.adservices.topics.TopicsManager.EMPTY_SDK;
import static android.adservices.topics.TopicsManager.RECORD_OBSERVATION_DEFAULT;

import android.annotation.NonNull;

/** Get Topics Request. */
public final class GetTopicsRequest {

    /** Name of Ads SDK that is involved in this request. */
    private final String mAdsSdkName;

    /** Whether to record that the caller has observed the topics of the host app or not. */
    private final boolean mRecordObservation;

    private GetTopicsRequest(@NonNull Builder builder) {
        mAdsSdkName = builder.mAdsSdkName;
        mRecordObservation = builder.mRecordObservation;
    }

    /** Get the Sdk Name. */
    @NonNull
    public String getAdsSdkName() {
        return mAdsSdkName;
    }

    /** Get Record Observation. */
    public boolean shouldRecordObservation() {
        return mRecordObservation;
    }

    /** Builder for {@link GetTopicsRequest} objects. */
    public static final class Builder {
        private String mAdsSdkName = EMPTY_SDK;
        private boolean mRecordObservation = RECORD_OBSERVATION_DEFAULT;

        /** Creates a {@link Builder} for {@link GetTopicsRequest} objects. */
        public Builder() {}

        /**
         * Set Ads Sdk Name.
         *
         * <p>This must be called by SDKs running outside of the Sandbox. Other clients must not
         * call it.
         *
         * @param adsSdkName the Ads Sdk Name.
         */
        @NonNull
        public Builder setAdsSdkName(@NonNull String adsSdkName) {
            // This is the case the SDK calling from outside of the Sandbox.
            // Check if the caller set the adsSdkName
            if (adsSdkName == null) {
                throw new IllegalArgumentException(
                        "When calling Topics API outside of the Sandbox, caller should set Ads Sdk"
                                + " Name");
            }

            mAdsSdkName = adsSdkName;
            return this;
        }

        /**
         * Set the Record Observation.
         *
         * @param recordObservation whether to record that the caller has observed the topics of the
         *     host app or not. This will be used to determine if the caller can receive the topic
         *     in the next epoch.
         */
        @NonNull
        public Builder setShouldRecordObservation(boolean recordObservation) {
            mRecordObservation = recordObservation;
            return this;
        }

        /** Builds a {@link GetTopicsRequest} instance. */
        @NonNull
        public GetTopicsRequest build() {
            return new GetTopicsRequest(this);
        }
    }
}