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 21 import androidx.test.platform.app.InstrumentationRegistry; 22 23 /** Helper to check if device is enabled or supports OnDevicePersonalization module */ 24 public final class DeviceSupportHelper { 25 26 /** 27 * Check whether the device is supported. 28 * OnDevicePersonalization module doesn't support Wear, Auto, TV, Go device 29 * @return if the device is supported. 30 */ isDeviceSupported()31 public static boolean isDeviceSupported() { 32 final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); 33 final PackageManager pm = instrumentation.getContext().getPackageManager(); 34 return !pm.hasSystemFeature(PackageManager.FEATURE_WATCH) 35 && !pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE) 36 // Android TV 37 && !pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK) 38 // Android Go 39 && !pm.hasSystemFeature(PackageManager.FEATURE_RAM_LOW); 40 } 41 } 42