1 /* 2 * Copyright 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 androidx.privacysandbox.ads.adservices.adselection 18 19 import android.os.Build 20 import android.os.ext.SdkExtensions 21 import androidx.annotation.RequiresExtension 22 import androidx.annotation.RestrictTo 23 import androidx.privacysandbox.ads.adservices.common.AdTechIdentifier 24 import androidx.privacysandbox.ads.adservices.common.ExperimentalFeatures 25 26 /** 27 * Represent input parameters to the [AdSelectionManager#persistAdSelectionResult] API. 28 * 29 * @param adSelectionId An ID unique only to a device user that identifies a successful ad 30 * selection. 31 * @param seller AdTechIdentifier of the seller, for example "www.example-ssp.com". 32 * @param adSelectionResult The adSelectionResult that is collected from device. 33 */ 34 @ExperimentalFeatures.Ext10OptIn 35 class PersistAdSelectionResultRequest 36 @JvmOverloads 37 public constructor( 38 val adSelectionId: Long, 39 val seller: AdTechIdentifier? = null, 40 val adSelectionResult: ByteArray? = null, 41 ) { 42 /** Checks whether two [PersistAdSelectionResultRequest] contain the same information. */ equalsnull43 override fun equals(other: Any?): Boolean { 44 if (this === other) return true 45 if (other !is PersistAdSelectionResultRequest) return false 46 return this.adSelectionId == other.adSelectionId && 47 this.seller == other.seller && 48 this.adSelectionResult.contentEquals(other.adSelectionResult) 49 } 50 51 /** Returns the hash of the [PersistAdSelectionResultRequest] object's data. */ hashCodenull52 override fun hashCode(): Int { 53 var hash = adSelectionId.hashCode() 54 hash = 31 * hash + seller.hashCode() 55 hash = 31 * hash + adSelectionResult.hashCode() 56 return hash 57 } 58 59 /** Overrides the toString method. */ toStringnull60 override fun toString(): String { 61 return "PersistAdSelectionResultRequest: adSelectionId=$adSelectionId, " + 62 "seller=$seller, adSelectionResult=$adSelectionResult" 63 } 64 65 @RestrictTo(RestrictTo.Scope.LIBRARY) 66 @RequiresExtension(extension = SdkExtensions.AD_SERVICES, version = 10) 67 @RequiresExtension(extension = Build.VERSION_CODES.S, version = 10) convertToAdServicesnull68 internal fun convertToAdServices(): 69 android.adservices.adselection.PersistAdSelectionResultRequest { 70 @Suppress("DEPRECATION") 71 return android.adservices.adselection.PersistAdSelectionResultRequest.Builder() 72 .setAdSelectionId(adSelectionId) 73 .setSeller(seller?.convertToAdServices()) 74 .setAdSelectionResult(adSelectionResult) 75 .build() 76 } 77 } 78