1/* 2 * Copyright (C) 2014 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 17package android.media; 18 19import android.util.SparseIntArray; 20 21/** 22 * Class to provide information about the audio devices. 23 * @hide 24 */ 25public class AudioDevice { 26 27 /** 28 * A device type associated with an unknown or uninitialized device. 29 */ 30 public static final int TYPE_UNKNOWN = 0; 31 /** 32 * A device type describing the attached earphone speaker. 33 */ 34 public static final int TYPE_BUILTIN_EARPIECE = 1; 35 /** 36 * A device type describing the speaker system (i.e. a mono speaker or stereo speakers) built 37 * in a device. 38 */ 39 public static final int TYPE_BUILTIN_SPEAKER = 2; 40 /** 41 * A device type describing a headset, which is the combination of a headphones and microphone. 42 */ 43 public static final int TYPE_WIRED_HEADSET = 3; 44 /** 45 * A device type describing a pair of wired headphones . 46 */ 47 public static final int TYPE_WIRED_HEADPHONES = 4; 48 /** 49 * A device type describing an analog line-level connection. 50 */ 51 public static final int TYPE_LINE_ANALOG = 5; 52 /** 53 * A device type describing a digital line connection (e.g. SPDIF). 54 */ 55 public static final int TYPE_LINE_DIGITAL = 6; 56 /** 57 * A device type describing a Bluetooth device typically used for telephony . 58 */ 59 public static final int TYPE_BLUETOOTH_SCO = 7; 60 /** 61 * A device type describing a Bluetooth device supporting the A2DP profile. 62 */ 63 public static final int TYPE_BLUETOOTH_A2DP = 8; 64 /** 65 * A device type describing an HDMI connection . 66 */ 67 public static final int TYPE_HDMI = 9; 68 /** 69 * A device type describing the Audio Return Channel of an HDMI connection. 70 */ 71 public static final int TYPE_HDMI_ARC = 10; 72 /** 73 * A device type describing a USB audio device. 74 */ 75 public static final int TYPE_USB_DEVICE = 11; 76 /** 77 * A device type describing a USB audio device in accessory mode. 78 */ 79 public static final int TYPE_USB_ACCESSORY = 12; 80 /** 81 * A device type describing the audio device associated with a dock. 82 */ 83 public static final int TYPE_DOCK = 13; 84 /** 85 * A device type associated with the transmission of audio signals over FM. 86 */ 87 public static final int TYPE_FM = 14; 88 /** 89 * A device type describing the microphone(s) built in a device. 90 */ 91 public static final int TYPE_BUILTIN_MIC = 15; 92 /** 93 * A device type for accessing the audio content transmitted over FM. 94 */ 95 public static final int TYPE_FM_TUNER = 16; 96 /** 97 * A device type for accessing the audio content transmitted over the TV tuner system. 98 */ 99 public static final int TYPE_TV_TUNER = 17; 100 /** 101 * A device type describing the transmission of audio signals over the telephony network. 102 */ 103 public static final int TYPE_TELEPHONY = 18; 104 /** 105 * A device type describing the auxiliary line-level connectors. 106 */ 107 public static final int TYPE_AUX_LINE = 19; 108 109 AudioDevicePortConfig mConfig; 110 111 AudioDevice(AudioDevicePortConfig config) { 112 mConfig = new AudioDevicePortConfig(config); 113 } 114 115 /** 116 * @hide 117 * CANDIDATE FOR PUBLIC API 118 * @return 119 */ 120 public boolean isInputDevice() { 121 return (mConfig.port().role() == AudioPort.ROLE_SOURCE); 122 } 123 124 /** 125 * @hide 126 * CANDIDATE FOR PUBLIC API 127 * @return 128 */ 129 public boolean isOutputDevice() { 130 return (mConfig.port().role() == AudioPort.ROLE_SINK); 131 } 132 133 /** 134 * @hide 135 * CANDIDATE FOR PUBLIC API 136 * @return 137 */ 138 public int getDeviceType() { 139 return INT_TO_EXT_DEVICE_MAPPING.get(mConfig.port().type(), TYPE_UNKNOWN); 140 } 141 142 /** 143 * @hide 144 * CANDIDATE FOR PUBLIC API 145 * @return 146 */ 147 public String getAddress() { 148 return mConfig.port().address(); 149 } 150 151 /** @hide */ 152 public static int convertDeviceTypeToInternalDevice(int deviceType) { 153 return EXT_TO_INT_DEVICE_MAPPING.get(deviceType, AudioSystem.DEVICE_NONE); 154 } 155 156 /** @hide */ 157 public static int convertInternalDeviceToDeviceType(int intDevice) { 158 return INT_TO_EXT_DEVICE_MAPPING.get(intDevice, TYPE_UNKNOWN); 159 } 160 161 private static final SparseIntArray INT_TO_EXT_DEVICE_MAPPING; 162 163 private static final SparseIntArray EXT_TO_INT_DEVICE_MAPPING; 164 165 static { 166 INT_TO_EXT_DEVICE_MAPPING = new SparseIntArray(); 167 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_EARPIECE, TYPE_BUILTIN_EARPIECE); 168 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_SPEAKER, TYPE_BUILTIN_SPEAKER); 169 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_WIRED_HEADSET, TYPE_WIRED_HEADSET); 170 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE, TYPE_WIRED_HEADPHONES); 171 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO, TYPE_BLUETOOTH_SCO); 172 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_HEADSET, TYPE_BLUETOOTH_SCO); 173 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_CARKIT, TYPE_BLUETOOTH_SCO); 174 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, TYPE_BLUETOOTH_A2DP); 175 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, TYPE_BLUETOOTH_A2DP); 176 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER, TYPE_BLUETOOTH_A2DP); 177 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_HDMI, TYPE_HDMI); 178 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET, TYPE_DOCK); 179 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET, TYPE_DOCK); 180 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_USB_ACCESSORY, TYPE_USB_ACCESSORY); 181 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_USB_DEVICE, TYPE_USB_DEVICE); 182 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_TELEPHONY_TX, TYPE_TELEPHONY); 183 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_LINE, TYPE_LINE_ANALOG); 184 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_HDMI_ARC, TYPE_HDMI_ARC); 185 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_SPDIF, TYPE_LINE_DIGITAL); 186 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_FM, TYPE_FM); 187 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_AUX_LINE, TYPE_AUX_LINE); 188 189 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BUILTIN_MIC, TYPE_BUILTIN_MIC); 190 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BLUETOOTH_SCO_HEADSET, TYPE_BLUETOOTH_SCO); 191 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_WIRED_HEADSET, TYPE_WIRED_HEADSET); 192 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_HDMI, TYPE_HDMI); 193 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_TELEPHONY_RX, TYPE_TELEPHONY); 194 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BACK_MIC, TYPE_BUILTIN_MIC); 195 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_ANLG_DOCK_HEADSET, TYPE_DOCK); 196 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_DGTL_DOCK_HEADSET, TYPE_DOCK); 197 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_USB_ACCESSORY, TYPE_USB_ACCESSORY); 198 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_USB_DEVICE, TYPE_USB_DEVICE); 199 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_FM_TUNER, TYPE_FM_TUNER); 200 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_TV_TUNER, TYPE_TV_TUNER); 201 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_LINE, TYPE_LINE_ANALOG); 202 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_SPDIF, TYPE_LINE_DIGITAL); 203 INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BLUETOOTH_A2DP, TYPE_BLUETOOTH_A2DP); 204 205 // not covered here, legacy 206 //AudioSystem.DEVICE_OUT_REMOTE_SUBMIX 207 //AudioSystem.DEVICE_IN_REMOTE_SUBMIX 208 209 // privileges mapping to output device 210 EXT_TO_INT_DEVICE_MAPPING = new SparseIntArray(); 211 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BUILTIN_EARPIECE, AudioSystem.DEVICE_OUT_EARPIECE); 212 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BUILTIN_SPEAKER, AudioSystem.DEVICE_OUT_SPEAKER); 213 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_WIRED_HEADSET, AudioSystem.DEVICE_OUT_WIRED_HEADSET); 214 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_WIRED_HEADPHONES, AudioSystem.DEVICE_OUT_WIRED_HEADPHONE); 215 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_LINE_ANALOG, AudioSystem.DEVICE_OUT_LINE); 216 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_LINE_DIGITAL, AudioSystem.DEVICE_OUT_SPDIF); 217 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BLUETOOTH_SCO, AudioSystem.DEVICE_OUT_BLUETOOTH_SCO); 218 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BLUETOOTH_A2DP, AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP); 219 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_HDMI, AudioSystem.DEVICE_OUT_HDMI); 220 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_HDMI_ARC, AudioSystem.DEVICE_OUT_HDMI_ARC); 221 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_USB_DEVICE, AudioSystem.DEVICE_OUT_USB_DEVICE); 222 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_USB_ACCESSORY, AudioSystem.DEVICE_OUT_USB_ACCESSORY); 223 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_DOCK, AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET); 224 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_FM, AudioSystem.DEVICE_OUT_FM); 225 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BUILTIN_MIC, AudioSystem.DEVICE_IN_BUILTIN_MIC); 226 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_FM_TUNER, AudioSystem.DEVICE_IN_FM_TUNER); 227 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_TV_TUNER, AudioSystem.DEVICE_IN_TV_TUNER); 228 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_TELEPHONY, AudioSystem.DEVICE_OUT_TELEPHONY_TX); 229 EXT_TO_INT_DEVICE_MAPPING.put(TYPE_AUX_LINE, AudioSystem.DEVICE_OUT_AUX_LINE); 230 } 231} 232 233