1 /* 2 * Copyright 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 androidx.privacysandbox.ads.adservices.topics 18 19 /** 20 * Represents the request for the getTopics API (which takes a [GetTopicsRequest] and returns a 21 * [GetTopicsResponse]. 22 * 23 * @param adsSdkName The Ads SDK name. This must be called by SDKs running outside of the Sandbox. 24 * Other clients must not call it. 25 * @param shouldRecordObservation whether to record that the caller has observed the topics of the 26 * host app or not. This will be used to determine if the caller can receive the topic in the next 27 * epoch. 28 */ 29 class GetTopicsRequest 30 public constructor( 31 val adsSdkName: String = "", 32 @get:JvmName("shouldRecordObservation") val shouldRecordObservation: Boolean = false 33 ) { toStringnull34 override fun toString(): String { 35 return "GetTopicsRequest: " + 36 "adsSdkName=$adsSdkName, shouldRecordObservation=$shouldRecordObservation" 37 } 38 equalsnull39 override fun equals(other: Any?): Boolean { 40 if (this === other) return true 41 if (other !is GetTopicsRequest) return false 42 return this.adsSdkName == other.adsSdkName && 43 this.shouldRecordObservation == other.shouldRecordObservation 44 } 45 hashCodenull46 override fun hashCode(): Int { 47 var hash = adsSdkName.hashCode() 48 hash = 31 * hash + shouldRecordObservation.hashCode() 49 return hash 50 } 51 52 /** Builder for [GetTopicsRequest]. */ 53 public class Builder() { 54 private var adsSdkName: String = "" 55 private var shouldRecordObservation: Boolean = true 56 57 /** 58 * Set Ads Sdk Name. 59 * 60 * <p>This must be called by SDKs running outside of the Sandbox. Other clients must not 61 * call it. 62 * 63 * @param adsSdkName the Ads Sdk Name. 64 */ <lambda>null65 fun setAdsSdkName(adsSdkName: String): Builder = apply { 66 check(adsSdkName.isNotEmpty()) { "adsSdkName must be set" } 67 this.adsSdkName = adsSdkName 68 } 69 70 /** 71 * Set the Record Observation. 72 * 73 * @param shouldRecordObservation whether to record that the caller has observed the topics 74 * of the host app or not. This will be used to determine if the caller can receive the 75 * topic in the next epoch. 76 */ 77 @Suppress("MissingGetterMatchingBuilder") <lambda>null78 fun setShouldRecordObservation(shouldRecordObservation: Boolean): Builder = apply { 79 this.shouldRecordObservation = shouldRecordObservation 80 } 81 82 /** Builds a [GetTopicsRequest] instance. */ buildnull83 fun build(): GetTopicsRequest { 84 return GetTopicsRequest(adsSdkName, shouldRecordObservation) 85 } 86 } 87 } 88