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.java 18 19 import android.os.Build 20 import android.os.ext.SdkExtensions 21 import androidx.test.filters.SdkSuppress 22 23 @SdkSuppress(minSdkVersion = 30) 24 object VersionCompatUtil { isTPlusWithMinAdServicesVersionnull25 fun isTPlusWithMinAdServicesVersion(minVersion: Int): Boolean { 26 return Build.VERSION.SDK_INT >= 33 && 27 SdkExtensions.getExtensionVersion(SdkExtensions.AD_SERVICES) >= minVersion 28 } 29 isSWithMinExtServicesVersionnull30 fun isSWithMinExtServicesVersion(minVersion: Int): Boolean { 31 return (Build.VERSION.SDK_INT == 31 || Build.VERSION.SDK_INT == 32) && 32 SdkExtensions.getExtensionVersion(Build.VERSION_CODES.S) >= minVersion 33 } 34 35 // Helper method to determine if version is testable, for APIs that are S+ only isTestableVersionnull36 fun isTestableVersion(minAdServicesVersion: Int, minExtServicesVersion: Int): Boolean { 37 return isTPlusWithMinAdServicesVersion(minAdServicesVersion) || 38 isSWithMinExtServicesVersion(minExtServicesVersion) 39 } 40 } 41