@@ -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