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.ExperimentalFeatures 24 25 /** 26 * This class represents the output of the [AdSelectionManager#getAdSelectionData] in the 27 * [AdSelectionManager]. The fields are populated in the case of a successful 28 * [AdSelectionManager#getAdSelectionData] call. 29 * 30 * @param adSelectionId An ID unique only to a device user that identifies a successful ad 31 * selection. 32 * @param adSelectionData The adSelectionData that is collected from device. 33 */ 34 @ExperimentalFeatures.Ext10OptIn 35 class GetAdSelectionDataOutcome 36 @JvmOverloads 37 public constructor(val adSelectionId: Long, val adSelectionData: ByteArray? = null) { 38 39 /** Checks whether two [GetAdSelectionDataOutcome] objects contain the same information. */ equalsnull40 override fun equals(other: Any?): Boolean { 41 if (this === other) return true 42 if (other !is GetAdSelectionDataOutcome) return false 43 return this.adSelectionId == other.adSelectionId && 44 this.adSelectionData.contentEquals(other.adSelectionData) 45 } 46 47 /** Returns the hash of the [GetAdSelectionDataOutcome] object's data. */ hashCodenull48 override fun hashCode(): Int { 49 var hash = adSelectionId.hashCode() 50 hash = 31 * hash + adSelectionData.hashCode() 51 return hash 52 } 53 54 /** Overrides the toString method. */ toStringnull55 override fun toString(): String { 56 return "GetAdSelectionDataOutcome: adSelectionId=$adSelectionId, " + 57 "adSelectionData=$adSelectionData" 58 } 59 60 @Suppress("DEPRECATION") 61 @RestrictTo(RestrictTo.Scope.LIBRARY) 62 @RequiresExtension(extension = SdkExtensions.AD_SERVICES, version = 10) 63 @RequiresExtension(extension = Build.VERSION_CODES.S, version = 10) 64 internal constructor( 65 response: android.adservices.adselection.GetAdSelectionDataOutcome 66 ) : this(response.adSelectionId, response.adSelectionData) 67 } 68