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.measurement 18 19 import android.annotation.SuppressLint 20 import android.net.Uri 21 import android.os.Build 22 import android.os.ext.SdkExtensions 23 import androidx.annotation.RequiresExtension 24 25 /** 26 * Class holding source registration parameters. 27 * 28 * @param registrationUri URI that the Attribution Reporting API sends a request to in order to 29 * obtain source registration parameters. 30 * @param debugKeyAllowed Used by the browser to indicate whether the debug key obtained from the 31 * registration URI is allowed to be used. 32 */ 33 class WebSourceParams public constructor(val registrationUri: Uri, val debugKeyAllowed: Boolean) { 34 equalsnull35 override fun equals(other: Any?): Boolean { 36 if (this === other) return true 37 if (other !is WebSourceParams) return false 38 return this.registrationUri == other.registrationUri && 39 this.debugKeyAllowed == other.debugKeyAllowed 40 } 41 hashCodenull42 override fun hashCode(): Int { 43 var hash = registrationUri.hashCode() 44 hash = 31 * hash + debugKeyAllowed.hashCode() 45 return hash 46 } 47 toStringnull48 override fun toString(): String { 49 return "WebSourceParams { RegistrationUri=$registrationUri, " + 50 "DebugKeyAllowed=$debugKeyAllowed }" 51 } 52 53 internal companion object { 54 @SuppressLint("NewApi") 55 @RequiresExtension(extension = SdkExtensions.AD_SERVICES, version = 4) 56 @RequiresExtension(extension = Build.VERSION_CODES.S, version = 9) convertWebSourceParamsnull57 internal fun convertWebSourceParams( 58 request: List<WebSourceParams> 59 ): List<android.adservices.measurement.WebSourceParams> { 60 var result = mutableListOf<android.adservices.measurement.WebSourceParams>() 61 for (param in request) { 62 result.add( 63 android.adservices.measurement.WebSourceParams.Builder(param.registrationUri) 64 .setDebugKeyAllowed(param.debugKeyAllowed) 65 .build() 66 ) 67 } 68 return result 69 } 70 } 71 } 72