1 /* 2 * Copyright (C) 2016 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 android.media.cts; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.content.IntentFilter; 22 import android.content.pm.PackageManager; 23 import android.media.AudioDeviceInfo; 24 import android.media.AudioManager; 25 26 public class DeviceUtils { 27 private static final String TAG = "DeviceUtils"; 28 hasOutputDevice(AudioManager audioMgr)29 public static boolean hasOutputDevice(AudioManager audioMgr) { 30 AudioDeviceInfo[] devices = audioMgr.getDevices(AudioManager.GET_DEVICES_OUTPUTS); 31 return devices.length != 0; 32 } 33 hasInputDevice(AudioManager audioMgr)34 public static boolean hasInputDevice(AudioManager audioMgr) { 35 AudioDeviceInfo[] devices = audioMgr.getDevices(AudioManager.GET_DEVICES_INPUTS); 36 return devices.length != 0; 37 } 38 isTVDevice(Context context)39 public static boolean isTVDevice(Context context) { 40 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK); 41 } 42 43 /* 44 * HDMI 45 */ isHDMIConnected(Context context)46 public static boolean isHDMIConnected(Context context) { 47 // configure the IntentFilter 48 IntentFilter intentFilter = new IntentFilter(); 49 intentFilter.addAction(AudioManager.ACTION_HDMI_AUDIO_PLUG); 50 Intent intent = context.registerReceiver(null, intentFilter); 51 52 return intent != null && intent.getIntExtra(AudioManager.EXTRA_AUDIO_PLUG_STATE, 0) != 0; 53 } 54 } 55