1 /* 2 * Copyright (C) 2021 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 com.android.cts.verifier.audio.audiolib; 18 19 import android.content.Context; 20 import android.content.pm.PackageManager; 21 import android.util.DisplayMetrics; 22 23 public class AudioSystemFlags { 24 static final String TAG = AudioSystemFlags.class.getName(); 25 26 private static final float MIN_TV_DIMENSION = 20; 27 claimsOutput(Context context)28 public static boolean claimsOutput(Context context) { 29 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT); 30 } 31 claimsInput(Context context)32 public static boolean claimsInput(Context context) { 33 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE); 34 } 35 claimsProAudio(Context context)36 public static boolean claimsProAudio(Context context) { 37 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUDIO_PRO); 38 } 39 claimsLowLatencyAudio(Context context)40 public static boolean claimsLowLatencyAudio(Context context) { 41 // CDD Section C-1-1: android.hardware.audio.low_latency 42 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUDIO_LOW_LATENCY); 43 } 44 claimsMIDI(Context context)45 public static boolean claimsMIDI(Context context) { 46 // CDD Section C-1-4: android.software.midi 47 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI); 48 } 49 claimsUSBHostMode(Context context)50 public static boolean claimsUSBHostMode(Context context) { 51 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_HOST); 52 } 53 claimsUSBPeripheralMode(Context context)54 public static boolean claimsUSBPeripheralMode(Context context) { 55 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY); 56 } 57 58 /** 59 * @param context The Context of the application. 60 * @return true if the device is a watch 61 */ isWatch(Context context)62 public static boolean isWatch(Context context) { 63 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH); 64 } 65 66 /** 67 * @param context The Context of the application. 68 * @return true if the device is Android Auto 69 */ isAutomobile(Context context)70 public static boolean isAutomobile(Context context) { 71 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); 72 } 73 74 /** 75 * @param context The Context of the application. 76 * @return true if the device is a TV 77 */ isTV(Context context)78 public static boolean isTV(Context context) { 79 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK); 80 } 81 82 /** 83 * @param context The Context of the application. 84 * @return true if the device is a handheld (Phone or tablet) 85 */ isHandheld(Context context)86 public static boolean isHandheld(Context context) { 87 DisplayMetrics metrics = context.getResources().getDisplayMetrics(); 88 float widthInInches = metrics.widthPixels / metrics.xdpi; 89 float heightInInches = metrics.heightPixels / metrics.ydpi; 90 91 // it is handheld if 92 // 1. it is not identified as any of those special devices 93 // 2. and it is small enough to actually hold in your hand. 94 return !(isWatch(context) || isAutomobile(context) || isTV(context)) 95 && (widthInInches < MIN_TV_DIMENSION && heightInInches < MIN_TV_DIMENSION); 96 } 97 } 98