Skip to content

Commit bab0111

Browse files
jmtriviAndroid (Google) Code Review
authored andcommitted
Merge "HDMI plug intent and associated information" into lmp-dev
2 parents 9401042 + 37d7804 commit bab0111

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7702,6 +7702,7 @@ package android.content {
77027702
field public static final java.lang.String ACTION_GET_RESTRICTION_ENTRIES = "android.intent.action.GET_RESTRICTION_ENTRIES";
77037703
field public static final java.lang.String ACTION_GTALK_SERVICE_CONNECTED = "android.intent.action.GTALK_CONNECTED";
77047704
field public static final java.lang.String ACTION_GTALK_SERVICE_DISCONNECTED = "android.intent.action.GTALK_DISCONNECTED";
7705+
field public static final java.lang.String ACTION_HDMI_AUDIO_PLUG = "android.intent.action.HDMI_AUDIO_PLUG";
77057706
field public static final java.lang.String ACTION_HEADSET_PLUG = "android.intent.action.HEADSET_PLUG";
77067707
field public static final java.lang.String ACTION_INPUT_METHOD_CHANGED = "android.intent.action.INPUT_METHOD_CHANGED";
77077708
field public static final java.lang.String ACTION_INSERT = "android.intent.action.INSERT";

core/java/android/content/Intent.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,15 +2279,20 @@ public static Intent createChooser(Intent target, CharSequence title) {
22792279
"android.intent.action.DIGITAL_AUDIO_DOCK_PLUG";
22802280

22812281
/**
2282-
* Broadcast Action: A HMDI cable was plugged or unplugged
2282+
* Broadcast Action: A sticky broadcast indicating an HMDI cable was plugged or unplugged
22832283
*
22842284
* <p>The intent will have the following extra values:
22852285
* <ul>
22862286
* <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
22872287
* <li><em>name</em> - HDMI cable, human readable string </li>
2288+
* <li><em>maxChannelCount</em> - the maximum number of output channels supported by the
2289+
* connected HDMI device, only available when <i>state</i> is 1.</li>
2290+
* <li><em>encodings</em> - an array of formats supported by the connected HDMI device,
2291+
* only available when <i>state</i> is 1. Encoding values are defined in
2292+
* {@link android.media.AudioFormat} (for instance see
2293+
* {@link android.media.AudioFormat#ENCODING_PCM_16BIT}). Use
2294+
* {@link #getIntArrayExtra(String)} to retrieve the encoding values.</li>
22882295
* </ul>
2289-
* </ul>
2290-
* @hide
22912296
*/
22922297
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
22932298
public static final String ACTION_HDMI_AUDIO_PLUG =

media/java/android/media/AudioService.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4389,7 +4389,7 @@ private void sendDeviceConnectionIntent(int device, int state, String name)
43894389
intent.setAction(Intent.ACTION_DIGITAL_AUDIO_DOCK_PLUG);
43904390
} else if (device == AudioSystem.DEVICE_OUT_HDMI) {
43914391
connType = AudioRoutesInfo.MAIN_HDMI;
4392-
intent.setAction(Intent.ACTION_HDMI_AUDIO_PLUG);
4392+
configureHdmiPlugIntent(intent, state);
43934393
}
43944394

43954395
synchronized (mCurAudioRoutes) {
@@ -4471,6 +4471,49 @@ private void onSetWiredDeviceConnectionState(int device, int state, String name)
44714471
}
44724472
}
44734473

4474+
private void configureHdmiPlugIntent(Intent intent, int state) {
4475+
intent.setAction(Intent.ACTION_HDMI_AUDIO_PLUG);
4476+
if (state == 1) {
4477+
ArrayList<AudioPort> ports = new ArrayList<AudioPort>();
4478+
int[] portGeneration = new int[1];
4479+
int status = AudioSystem.listAudioPorts(ports, portGeneration);
4480+
if (status == AudioManager.SUCCESS) {
4481+
for (AudioPort port : ports) {
4482+
if (port instanceof AudioDevicePort) {
4483+
final AudioDevicePort devicePort = (AudioDevicePort) port;
4484+
if (devicePort.type() == AudioManager.DEVICE_OUT_HDMI) {
4485+
// format the list of supported encodings
4486+
int[] formats = devicePort.formats();
4487+
if (formats.length > 0) {
4488+
ArrayList<Integer> encodingList = new ArrayList(1);
4489+
for (int format : formats) {
4490+
// a format in the list can be 0, skip it
4491+
if (format != AudioFormat.ENCODING_INVALID) {
4492+
encodingList.add(format);
4493+
}
4494+
}
4495+
int[] encodingArray = new int[encodingList.size()];
4496+
for (int i = 0 ; i < encodingArray.length ; i++) {
4497+
encodingArray[i] = encodingList.get(i);
4498+
}
4499+
intent.putExtra("encodings", encodingArray);
4500+
}
4501+
// find the maximum supported number of channels
4502+
int maxChannels = 0;
4503+
for (int mask : devicePort.channelMasks()) {
4504+
int channelCount = AudioFormat.channelCountFromOutChannelMask(mask);
4505+
if (channelCount > maxChannels) {
4506+
maxChannels = channelCount;
4507+
}
4508+
}
4509+
intent.putExtra("maxChannelCount", maxChannels);
4510+
}
4511+
}
4512+
}
4513+
}
4514+
}
4515+
}
4516+
44744517
/* cache of the address of the last dock the device was connected to */
44754518
private String mDockAddress;
44764519

0 commit comments

Comments
 (0)