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