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 
17 package android.media;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.util.SparseIntArray;
22 
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.RetentionPolicy;
25 import java.util.Objects;
26 import java.util.TreeSet;
27 
28 /**
29  * Class to provide information about the audio devices.
30  */
31 public final class AudioDeviceInfo {
32 
33     /**
34      * A device type associated with an unknown or uninitialized device.
35      */
36     public static final int TYPE_UNKNOWN          = 0;
37     /**
38      * A device type describing the attached earphone speaker.
39      */
40     public static final int TYPE_BUILTIN_EARPIECE = 1;
41     /**
42      * A device type describing the speaker system (i.e. a mono speaker or stereo speakers) built
43      * in a device.
44      */
45     public static final int TYPE_BUILTIN_SPEAKER  = 2;
46     /**
47      * A device type describing a headset, which is the combination of a headphones and microphone.
48      */
49     public static final int TYPE_WIRED_HEADSET    = 3;
50     /**
51      * A device type describing a pair of wired headphones.
52      */
53     public static final int TYPE_WIRED_HEADPHONES = 4;
54     /**
55      * A device type describing an analog line-level connection.
56      */
57     public static final int TYPE_LINE_ANALOG      = 5;
58     /**
59      * A device type describing a digital line connection (e.g. SPDIF).
60      */
61     public static final int TYPE_LINE_DIGITAL     = 6;
62     /**
63      * A device type describing a Bluetooth device typically used for telephony.
64      */
65     public static final int TYPE_BLUETOOTH_SCO    = 7;
66     /**
67      * A device type describing a Bluetooth device supporting the A2DP profile.
68      */
69     public static final int TYPE_BLUETOOTH_A2DP   = 8;
70     /**
71      * A device type describing an HDMI connection .
72      */
73     public static final int TYPE_HDMI             = 9;
74     /**
75      * A device type describing the Audio Return Channel of an HDMI connection.
76      */
77     public static final int TYPE_HDMI_ARC         = 10;
78     /**
79      * A device type describing a USB audio device.
80      */
81     public static final int TYPE_USB_DEVICE       = 11;
82     /**
83      * A device type describing a USB audio device in accessory mode.
84      */
85     public static final int TYPE_USB_ACCESSORY    = 12;
86     /**
87      * A device type describing the audio device associated with a dock.
88      */
89     public static final int TYPE_DOCK             = 13;
90     /**
91      * A device type associated with the transmission of audio signals over FM.
92      */
93     public static final int TYPE_FM               = 14;
94     /**
95      * A device type describing the microphone(s) built in a device.
96      */
97     public static final int TYPE_BUILTIN_MIC      = 15;
98     /**
99      * A device type for accessing the audio content transmitted over FM.
100      */
101     public static final int TYPE_FM_TUNER         = 16;
102     /**
103      * A device type for accessing the audio content transmitted over the TV tuner system.
104      */
105     public static final int TYPE_TV_TUNER         = 17;
106     /**
107      * A device type describing the transmission of audio signals over the telephony network.
108      */
109     public static final int TYPE_TELEPHONY        = 18;
110     /**
111      * A device type describing the auxiliary line-level connectors.
112      */
113     public static final int TYPE_AUX_LINE         = 19;
114     /**
115      * A device type connected over IP.
116      */
117     public static final int TYPE_IP               = 20;
118     /**
119      * A type-agnostic device used for communication with external audio systems
120      */
121     public static final int TYPE_BUS              = 21;
122     /**
123      * A device type describing a USB audio headset.
124      */
125     public static final int TYPE_USB_HEADSET       = 22;
126     /**
127      * A device type describing a Hearing Aid.
128      */
129     public static final int TYPE_HEARING_AID   = 23;
130 
131     /** @hide */
132     @IntDef(flag = false, prefix = "TYPE", value = {
133             TYPE_BUILTIN_EARPIECE,
134             TYPE_BUILTIN_SPEAKER,
135             TYPE_WIRED_HEADSET,
136             TYPE_WIRED_HEADPHONES,
137             TYPE_BLUETOOTH_SCO,
138             TYPE_BLUETOOTH_A2DP,
139             TYPE_HDMI,
140             TYPE_DOCK,
141             TYPE_USB_ACCESSORY,
142             TYPE_USB_DEVICE,
143             TYPE_USB_HEADSET,
144             TYPE_TELEPHONY,
145             TYPE_LINE_ANALOG,
146             TYPE_HDMI_ARC,
147             TYPE_LINE_DIGITAL,
148             TYPE_FM,
149             TYPE_AUX_LINE,
150             TYPE_IP,
151             TYPE_BUS,
152             TYPE_HEARING_AID,
153             TYPE_BUILTIN_MIC,
154             TYPE_FM_TUNER,
155             TYPE_TV_TUNER }
156     )
157     @Retention(RetentionPolicy.SOURCE)
158     public @interface AudioDeviceType {}    /** @hide */
159     @IntDef(flag = false, prefix = "TYPE", value = {
160             TYPE_BUILTIN_MIC,
161             TYPE_BLUETOOTH_SCO,
162             TYPE_BLUETOOTH_A2DP,
163             TYPE_WIRED_HEADSET,
164             TYPE_HDMI,
165             TYPE_TELEPHONY,
166             TYPE_DOCK,
167             TYPE_USB_ACCESSORY,
168             TYPE_USB_DEVICE,
169             TYPE_USB_HEADSET,
170             TYPE_FM_TUNER,
171             TYPE_TV_TUNER,
172             TYPE_LINE_ANALOG,
173             TYPE_LINE_DIGITAL,
174             TYPE_IP,
175             TYPE_BUS }
176     )
177     @Retention(RetentionPolicy.SOURCE)
178     public @interface AudioDeviceTypeIn {}
179 
180     /** @hide */
181     @IntDef(flag = false, prefix = "TYPE", value = {
182             TYPE_BUILTIN_EARPIECE,
183             TYPE_BUILTIN_SPEAKER,
184             TYPE_WIRED_HEADSET,
185             TYPE_WIRED_HEADPHONES,
186             TYPE_BLUETOOTH_SCO,
187             TYPE_BLUETOOTH_A2DP,
188             TYPE_HDMI,
189             TYPE_DOCK,
190             TYPE_USB_ACCESSORY,
191             TYPE_USB_DEVICE,
192             TYPE_USB_HEADSET,
193             TYPE_TELEPHONY,
194             TYPE_LINE_ANALOG,
195             TYPE_HDMI_ARC,
196             TYPE_LINE_DIGITAL,
197             TYPE_FM,
198             TYPE_AUX_LINE,
199             TYPE_IP,
200             TYPE_BUS,
201             TYPE_HEARING_AID }
202     )
203     @Retention(RetentionPolicy.SOURCE)
204     public @interface AudioDeviceTypeOut {}
205 
206     /** @hide */
isValidAudioDeviceTypeOut(int type)207     /*package*/ static boolean isValidAudioDeviceTypeOut(int type) {
208         switch (type) {
209             case TYPE_BUILTIN_EARPIECE:
210             case TYPE_BUILTIN_SPEAKER:
211             case TYPE_WIRED_HEADSET:
212             case TYPE_WIRED_HEADPHONES:
213             case TYPE_BLUETOOTH_SCO:
214             case TYPE_BLUETOOTH_A2DP:
215             case TYPE_HDMI:
216             case TYPE_DOCK:
217             case TYPE_USB_ACCESSORY:
218             case TYPE_USB_DEVICE:
219             case TYPE_USB_HEADSET:
220             case TYPE_TELEPHONY:
221             case TYPE_LINE_ANALOG:
222             case TYPE_HDMI_ARC:
223             case TYPE_LINE_DIGITAL:
224             case TYPE_FM:
225             case TYPE_AUX_LINE:
226             case TYPE_IP:
227             case TYPE_BUS:
228             case TYPE_HEARING_AID:
229                 return true;
230             default:
231                 return false;
232         }
233     }
234 
235     /** @hide */
isValidAudioDeviceTypeIn(int type)236     /*package*/ static boolean isValidAudioDeviceTypeIn(int type) {
237         switch (type) {
238             case TYPE_BUILTIN_MIC:
239             case TYPE_BLUETOOTH_SCO:
240             case TYPE_BLUETOOTH_A2DP:
241             case TYPE_WIRED_HEADSET:
242             case TYPE_HDMI:
243             case TYPE_TELEPHONY:
244             case TYPE_DOCK:
245             case TYPE_USB_ACCESSORY:
246             case TYPE_USB_DEVICE:
247             case TYPE_USB_HEADSET:
248             case TYPE_FM_TUNER:
249             case TYPE_TV_TUNER:
250             case TYPE_LINE_ANALOG:
251             case TYPE_LINE_DIGITAL:
252             case TYPE_IP:
253             case TYPE_BUS:
254                 return true;
255             default:
256                 return false;
257         }
258     }
259 
260     @Override
equals(Object o)261     public boolean equals(Object o) {
262         if (this == o) return true;
263         if (o == null || getClass() != o.getClass()) return false;
264         AudioDeviceInfo that = (AudioDeviceInfo) o;
265         return Objects.equals(getPort(), that.getPort());
266     }
267 
268     @Override
hashCode()269     public int hashCode() {
270         return Objects.hash(getPort());
271     }
272 
273     private final AudioDevicePort mPort;
274 
AudioDeviceInfo(AudioDevicePort port)275     AudioDeviceInfo(AudioDevicePort port) {
276        mPort = port;
277     }
278 
279     /**
280      * @hide
281      * @return The underlying {@link AudioDevicePort} instance.
282      */
getPort()283     public AudioDevicePort getPort() {
284         return mPort;
285     }
286 
287     /**
288      * @return The internal device ID.
289      */
getId()290     public int getId() {
291         return mPort.handle().id();
292     }
293 
294     /**
295      * @return The human-readable name of the audio device.
296      */
getProductName()297     public CharSequence getProductName() {
298         String portName = mPort.name();
299         return portName.length() != 0 ? portName : android.os.Build.MODEL;
300     }
301 
302     /**
303      * @return The "address" string of the device. This generally contains device-specific
304      * parameters.
305      */
getAddress()306     public @NonNull String getAddress() {
307         return mPort.address();
308     }
309 
310    /**
311      * @return true if the audio device is a source for audio data (e.e an input).
312      */
isSource()313     public boolean isSource() {
314         return mPort.role() == AudioPort.ROLE_SOURCE;
315     }
316 
317     /**
318      * @return true if the audio device is a sink for audio data (i.e. an output).
319      */
isSink()320     public boolean isSink() {
321         return mPort.role() == AudioPort.ROLE_SINK;
322     }
323 
324     /**
325      * @return An array of sample rates supported by the audio device.
326      *
327      * Note: an empty array indicates that the device supports arbitrary rates.
328      */
getSampleRates()329     public @NonNull int[] getSampleRates() {
330         return mPort.samplingRates();
331     }
332 
333     /**
334      * @return An array of channel position masks (e.g. {@link AudioFormat#CHANNEL_IN_STEREO},
335      * {@link AudioFormat#CHANNEL_OUT_7POINT1}) for which this audio device can be configured.
336      *
337      * @see AudioFormat
338      *
339      * Note: an empty array indicates that the device supports arbitrary channel masks.
340      */
getChannelMasks()341     public @NonNull int[] getChannelMasks() {
342         return mPort.channelMasks();
343     }
344 
345     /**
346      * @return An array of channel index masks for which this audio device can be configured.
347      *
348      * @see AudioFormat
349      *
350      * Note: an empty array indicates that the device supports arbitrary channel index masks.
351      */
getChannelIndexMasks()352     public @NonNull int[] getChannelIndexMasks() {
353         return mPort.channelIndexMasks();
354     }
355 
356     /**
357      * @return An array of channel counts (1, 2, 4, ...) for which this audio device
358      * can be configured.
359      *
360      * Note: an empty array indicates that the device supports arbitrary channel counts.
361      */
getChannelCounts()362     public @NonNull int[] getChannelCounts() {
363         TreeSet<Integer> countSet = new TreeSet<Integer>();
364 
365         // Channel Masks
366         for (int mask : getChannelMasks()) {
367             countSet.add(isSink() ?
368                     AudioFormat.channelCountFromOutChannelMask(mask)
369                     : AudioFormat.channelCountFromInChannelMask(mask));
370         }
371 
372         // Index Masks
373         for (int index_mask : getChannelIndexMasks()) {
374             countSet.add(Integer.bitCount(index_mask));
375         }
376 
377         int[] counts = new int[countSet.size()];
378         int index = 0;
379         for (int count : countSet) {
380             counts[index++] = count;
381         }
382         return counts;
383     }
384 
385     /**
386      * @return An array of audio encodings (e.g. {@link AudioFormat#ENCODING_PCM_16BIT},
387      * {@link AudioFormat#ENCODING_PCM_FLOAT}) supported by the audio device.
388      * <code>ENCODING_PCM_FLOAT</code> indicates the device supports more
389      * than 16 bits of integer precision.  As there is no AudioFormat constant
390      * specifically defined for 24-bit PCM, the value <code>ENCODING_PCM_FLOAT</code>
391      * indicates that {@link AudioTrack} or {@link AudioRecord} can preserve at least 24 bits of
392      * integer precision to that device.
393      *
394      * @see AudioFormat
395      *
396      * Note: an empty array indicates that the device supports arbitrary encodings.
397      */
getEncodings()398     public @NonNull int[] getEncodings() {
399         return AudioFormat.filterPublicFormats(mPort.formats());
400     }
401 
402    /**
403      * @return The device type identifier of the audio device (i.e. TYPE_BUILTIN_SPEAKER).
404      */
getType()405     public int getType() {
406         return INT_TO_EXT_DEVICE_MAPPING.get(mPort.type(), TYPE_UNKNOWN);
407     }
408 
409     /** @hide */
convertDeviceTypeToInternalDevice(int deviceType)410     public static int convertDeviceTypeToInternalDevice(int deviceType) {
411         return EXT_TO_INT_DEVICE_MAPPING.get(deviceType, AudioSystem.DEVICE_NONE);
412     }
413 
414     /** @hide */
convertInternalDeviceToDeviceType(int intDevice)415     public static int convertInternalDeviceToDeviceType(int intDevice) {
416         return INT_TO_EXT_DEVICE_MAPPING.get(intDevice, TYPE_UNKNOWN);
417     }
418 
419     private static final SparseIntArray INT_TO_EXT_DEVICE_MAPPING;
420 
421     private static final SparseIntArray EXT_TO_INT_DEVICE_MAPPING;
422 
423     static {
424         INT_TO_EXT_DEVICE_MAPPING = new SparseIntArray();
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_EARPIECE, TYPE_BUILTIN_EARPIECE)425         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_EARPIECE, TYPE_BUILTIN_EARPIECE);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_SPEAKER, TYPE_BUILTIN_SPEAKER)426         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_SPEAKER, TYPE_BUILTIN_SPEAKER);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_WIRED_HEADSET, TYPE_WIRED_HEADSET)427         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_WIRED_HEADSET, TYPE_WIRED_HEADSET);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE, TYPE_WIRED_HEADPHONES)428         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE, TYPE_WIRED_HEADPHONES);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO, TYPE_BLUETOOTH_SCO)429         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO, TYPE_BLUETOOTH_SCO);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_HEADSET, TYPE_BLUETOOTH_SCO)430         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_HEADSET, TYPE_BLUETOOTH_SCO);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_CARKIT, TYPE_BLUETOOTH_SCO)431         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_CARKIT, TYPE_BLUETOOTH_SCO);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, TYPE_BLUETOOTH_A2DP)432         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, TYPE_BLUETOOTH_A2DP);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, TYPE_BLUETOOTH_A2DP)433         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, TYPE_BLUETOOTH_A2DP);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER, TYPE_BLUETOOTH_A2DP)434         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER, TYPE_BLUETOOTH_A2DP);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_HDMI, TYPE_HDMI)435         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_HDMI, TYPE_HDMI);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET, TYPE_DOCK)436         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET, TYPE_DOCK);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET, TYPE_DOCK)437         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET, TYPE_DOCK);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_USB_ACCESSORY, TYPE_USB_ACCESSORY)438         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_USB_ACCESSORY, TYPE_USB_ACCESSORY);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_USB_DEVICE, TYPE_USB_DEVICE)439         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_USB_DEVICE, TYPE_USB_DEVICE);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_USB_HEADSET, TYPE_USB_HEADSET)440         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_USB_HEADSET, TYPE_USB_HEADSET);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_TELEPHONY_TX, TYPE_TELEPHONY)441         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_TELEPHONY_TX, TYPE_TELEPHONY);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_LINE, TYPE_LINE_ANALOG)442         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_LINE, TYPE_LINE_ANALOG);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_HDMI_ARC, TYPE_HDMI_ARC)443         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_HDMI_ARC, TYPE_HDMI_ARC);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_SPDIF, TYPE_LINE_DIGITAL)444         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_SPDIF, TYPE_LINE_DIGITAL);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_FM, TYPE_FM)445         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_FM, TYPE_FM);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_AUX_LINE, TYPE_AUX_LINE)446         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_AUX_LINE, TYPE_AUX_LINE);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_IP, TYPE_IP)447         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_IP, TYPE_IP);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BUS, TYPE_BUS)448         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_BUS, TYPE_BUS);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_HEARING_AID, TYPE_HEARING_AID)449         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_OUT_HEARING_AID, TYPE_HEARING_AID);
450 
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BUILTIN_MIC, TYPE_BUILTIN_MIC)451         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BUILTIN_MIC, TYPE_BUILTIN_MIC);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BLUETOOTH_SCO_HEADSET, TYPE_BLUETOOTH_SCO)452         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BLUETOOTH_SCO_HEADSET, TYPE_BLUETOOTH_SCO);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_WIRED_HEADSET, TYPE_WIRED_HEADSET)453         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_WIRED_HEADSET, TYPE_WIRED_HEADSET);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_HDMI, TYPE_HDMI)454         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_HDMI, TYPE_HDMI);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_TELEPHONY_RX, TYPE_TELEPHONY)455         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_TELEPHONY_RX, TYPE_TELEPHONY);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BACK_MIC, TYPE_BUILTIN_MIC)456         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BACK_MIC, TYPE_BUILTIN_MIC);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_ANLG_DOCK_HEADSET, TYPE_DOCK)457         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_ANLG_DOCK_HEADSET, TYPE_DOCK);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_DGTL_DOCK_HEADSET, TYPE_DOCK)458         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_DGTL_DOCK_HEADSET, TYPE_DOCK);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_USB_ACCESSORY, TYPE_USB_ACCESSORY)459         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_USB_ACCESSORY, TYPE_USB_ACCESSORY);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_USB_DEVICE, TYPE_USB_DEVICE)460         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_USB_DEVICE, TYPE_USB_DEVICE);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_USB_HEADSET, TYPE_USB_HEADSET)461         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_USB_HEADSET, TYPE_USB_HEADSET);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_FM_TUNER, TYPE_FM_TUNER)462         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_FM_TUNER, TYPE_FM_TUNER);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_TV_TUNER, TYPE_TV_TUNER)463         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_TV_TUNER, TYPE_TV_TUNER);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_LINE, TYPE_LINE_ANALOG)464         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_LINE, TYPE_LINE_ANALOG);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_SPDIF, TYPE_LINE_DIGITAL)465         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_SPDIF, TYPE_LINE_DIGITAL);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BLUETOOTH_A2DP, TYPE_BLUETOOTH_A2DP)466         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BLUETOOTH_A2DP, TYPE_BLUETOOTH_A2DP);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_IP, TYPE_IP)467         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_IP, TYPE_IP);
INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BUS, TYPE_BUS)468         INT_TO_EXT_DEVICE_MAPPING.put(AudioSystem.DEVICE_IN_BUS, TYPE_BUS);
469 
470         // not covered here, legacy
471         //AudioSystem.DEVICE_OUT_REMOTE_SUBMIX
472         //AudioSystem.DEVICE_IN_REMOTE_SUBMIX
473 
474         // privileges mapping to output device
475         EXT_TO_INT_DEVICE_MAPPING = new SparseIntArray();
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BUILTIN_EARPIECE, AudioSystem.DEVICE_OUT_EARPIECE)476         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BUILTIN_EARPIECE, AudioSystem.DEVICE_OUT_EARPIECE);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BUILTIN_SPEAKER, AudioSystem.DEVICE_OUT_SPEAKER)477         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BUILTIN_SPEAKER, AudioSystem.DEVICE_OUT_SPEAKER);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_WIRED_HEADSET, AudioSystem.DEVICE_OUT_WIRED_HEADSET)478         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_WIRED_HEADSET, AudioSystem.DEVICE_OUT_WIRED_HEADSET);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_WIRED_HEADPHONES, AudioSystem.DEVICE_OUT_WIRED_HEADPHONE)479         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_WIRED_HEADPHONES, AudioSystem.DEVICE_OUT_WIRED_HEADPHONE);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_LINE_ANALOG, AudioSystem.DEVICE_OUT_LINE)480         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_LINE_ANALOG, AudioSystem.DEVICE_OUT_LINE);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_LINE_DIGITAL, AudioSystem.DEVICE_OUT_SPDIF)481         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_LINE_DIGITAL, AudioSystem.DEVICE_OUT_SPDIF);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BLUETOOTH_SCO, AudioSystem.DEVICE_OUT_BLUETOOTH_SCO)482         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BLUETOOTH_SCO, AudioSystem.DEVICE_OUT_BLUETOOTH_SCO);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BLUETOOTH_A2DP, AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP)483         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BLUETOOTH_A2DP, AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_HDMI, AudioSystem.DEVICE_OUT_HDMI)484         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_HDMI, AudioSystem.DEVICE_OUT_HDMI);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_HDMI_ARC, AudioSystem.DEVICE_OUT_HDMI_ARC)485         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_HDMI_ARC, AudioSystem.DEVICE_OUT_HDMI_ARC);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_USB_DEVICE, AudioSystem.DEVICE_OUT_USB_DEVICE)486         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_USB_DEVICE, AudioSystem.DEVICE_OUT_USB_DEVICE);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_USB_HEADSET, AudioSystem.DEVICE_OUT_USB_HEADSET)487         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_USB_HEADSET, AudioSystem.DEVICE_OUT_USB_HEADSET);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_USB_ACCESSORY, AudioSystem.DEVICE_OUT_USB_ACCESSORY)488         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_USB_ACCESSORY, AudioSystem.DEVICE_OUT_USB_ACCESSORY);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_DOCK, AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET)489         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_DOCK, AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_FM, AudioSystem.DEVICE_OUT_FM)490         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_FM, AudioSystem.DEVICE_OUT_FM);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BUILTIN_MIC, AudioSystem.DEVICE_IN_BUILTIN_MIC)491         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BUILTIN_MIC, AudioSystem.DEVICE_IN_BUILTIN_MIC);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_FM_TUNER, AudioSystem.DEVICE_IN_FM_TUNER)492         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_FM_TUNER, AudioSystem.DEVICE_IN_FM_TUNER);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_TV_TUNER, AudioSystem.DEVICE_IN_TV_TUNER)493         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_TV_TUNER, AudioSystem.DEVICE_IN_TV_TUNER);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_TELEPHONY, AudioSystem.DEVICE_OUT_TELEPHONY_TX)494         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_TELEPHONY, AudioSystem.DEVICE_OUT_TELEPHONY_TX);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_AUX_LINE, AudioSystem.DEVICE_OUT_AUX_LINE)495         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_AUX_LINE, AudioSystem.DEVICE_OUT_AUX_LINE);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_IP, AudioSystem.DEVICE_OUT_IP)496         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_IP, AudioSystem.DEVICE_OUT_IP);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BUS, AudioSystem.DEVICE_OUT_BUS)497         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_BUS, AudioSystem.DEVICE_OUT_BUS);
EXT_TO_INT_DEVICE_MAPPING.put(TYPE_HEARING_AID, AudioSystem.DEVICE_OUT_HEARING_AID)498         EXT_TO_INT_DEVICE_MAPPING.put(TYPE_HEARING_AID, AudioSystem.DEVICE_OUT_HEARING_AID);
499     }
500 }
501 
502