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 // TODO(b/191301111): Rename this class to AudioSystemFeatures 24 25 public class AudioSystemFlags { 26 static final String TAG = AudioSystemFlags.class.getName(); 27 28 private static final float MIN_TV_DIMENSION = 20; 29 claimsOutput(Context context)30 public static boolean claimsOutput(Context context) { 31 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT); 32 } 33 claimsInput(Context context)34 public static boolean claimsInput(Context context) { 35 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE); 36 } 37 claimsProAudio(Context context)38 public static boolean claimsProAudio(Context context) { 39 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUDIO_PRO); 40 } 41 claimsLowLatencyAudio(Context context)42 public static boolean claimsLowLatencyAudio(Context context) { 43 // CDD Section C-1-1: android.hardware.audio.low_latency 44 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUDIO_LOW_LATENCY); 45 } 46 claimsMIDI(Context context)47 public static boolean claimsMIDI(Context context) { 48 // CDD Section C-1-4: android.software.midi 49 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI); 50 } 51 claimsUSBHostMode(Context context)52 public static boolean claimsUSBHostMode(Context context) { 53 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_HOST); 54 } 55 claimsUSBPeripheralMode(Context context)56 public static boolean claimsUSBPeripheralMode(Context context) { 57 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY); 58 } 59 60 /** 61 * Determines if the device has declared the FEATURE_AUDIO_SPATIAL_HEADTRACKING_LOW_LATENCY 62 * flag 63 * @param context The application context 64 * @return true if the PackageManager declares the system feature 65 * FEATURE_AUDIO_SPATIAL_HEADTRACKING_LOW_LATENCY 66 */ claimsHeadTrackingLowLatency(Context context)67 public static boolean claimsHeadTrackingLowLatency(Context context) { 68 // Do we need to test FLAG_FEATURE_SPATIAL_AUDIO_HEADTRACKING_LOW_LATENCY? 69 // what namespace is this flag defined in? 70 // if (!Flags.featureSpatialAudioHeadtrackingLowLatency()) { 71 // return false; 72 // } 73 return context.getPackageManager().hasSystemFeature( 74 PackageManager.FEATURE_AUDIO_SPATIAL_HEADTRACKING_LOW_LATENCY); 75 } 76 77 /** 78 * @param context The Context of the application. 79 * @return true if the device is a watch 80 */ isWatch(Context context)81 public static boolean isWatch(Context context) { 82 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH); 83 } 84 85 /** 86 * @param context The Context of the application. 87 * @return true if the platform supports the WebView control. 88 */ supportsWebView(Context context)89 public static boolean supportsWebView(Context context) { 90 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WEBVIEW); 91 } 92 93 /** 94 * @param context The Context of the application. 95 * @return true if the device is Android Auto 96 */ isAutomobile(Context context)97 public static boolean isAutomobile(Context context) { 98 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); 99 } 100 101 /** 102 * @param context The Context of the application. 103 * @return true if the device is a TV 104 */ isTV(Context context)105 public static boolean isTV(Context context) { 106 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK); 107 } 108 109 /** 110 * @param context The Context of the application. 111 * @return true if the device is a handheld (Phone or tablet) 112 */ isHandheld(Context context)113 public static boolean isHandheld(Context context) { 114 DisplayMetrics metrics = context.getResources().getDisplayMetrics(); 115 float widthInInches = metrics.widthPixels / metrics.xdpi; 116 float heightInInches = metrics.heightPixels / metrics.ydpi; 117 118 // it is handheld if 119 // 1. it is not identified as any of those special devices 120 // 2. and it is small enough to actually hold in your hand. 121 return !(isWatch(context) || isAutomobile(context) || isTV(context)) 122 && (widthInInches < MIN_TV_DIMENSION && heightInInches < MIN_TV_DIMENSION); 123 } 124 } 125