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