1 /* 2 * Copyright 2024 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 package com.android.ondevicepersonalization.testing.utils; 17 18 import android.app.Instrumentation; 19 import android.content.pm.PackageManager; 20 import android.os.Build; 21 import android.os.ext.SdkExtensions; 22 23 import androidx.test.platform.app.InstrumentationRegistry; 24 25 /** Helper to check if device is enabled or supports OnDevicePersonalization module */ 26 public final class DeviceSupportHelper { 27 private static final int MIN_SDK_EXT = 13; // M2024-08 28 29 /** 30 * Check whether the device is supported. 31 * OnDevicePersonalization module doesn't support Wear, Auto, TV, Go device 32 * @return if the device is supported. 33 */ isDeviceSupported()34 public static boolean isDeviceSupported() { 35 final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); 36 final PackageManager pm = instrumentation.getContext().getPackageManager(); 37 return !pm.hasSystemFeature(PackageManager.FEATURE_WATCH) 38 && !pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE) 39 // Android TV 40 && !pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK) 41 // Android Go 42 && !pm.hasSystemFeature(PackageManager.FEATURE_RAM_LOW); 43 } 44 45 /** 46 * Check whether the ODP module with public APIs is installed on the device. 47 * For CTS only. 48 */ isOdpModuleAvailable()49 public static boolean isOdpModuleAvailable() { 50 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM 51 || SdkExtensions.getExtensionVersion(SdkExtensions.AD_SERVICES) >= MIN_SDK_EXT; 52 } 53 } 54