libstagefright: Set session id to one for LPA playback

-ALSA HAL needs to differentiate between LPA and Tunnel mode
 playback for setting the correct routing path.
-The session id for LPA playback is set to one.

CRs-Fixed: 352002
(cherry picked from commit 5382f7f8feb609dfecae961641b0b5b0b6218371)

Change-Id: Id8b88ad838ce307b907444d4c5b9e25c3c3a19f3
libstagefright: Fix for seek before end of clip issue

- When the clip is seeked to just before the end of the clip,
  the control skips to next track instead of the remaining part
  of the clip being played.
- When the clip is seeked, in LPAPlayerALSA, fillBuffer() is
  called which sets mReachedEOS to true when the last buffer
  is reached. AwesomePlayer on the other hand calls
  onCheckAudioStatus() after seek complete which in turn
  checks if reachedEOS() returns true in LPAPlayerALSA and
  calls postStreamDoneEvent(). Currently, reachedEOS() returns
  mReachedEOS which is incorrect because there still are
  buffers to be written to the DSP.
- Before postAudioEOS() is called, mReachedOutputEOS is set to
  true and is returned by reachedEOS().

CRs-Fixed: 339602 359591
(cherry picked from commit fe2345716be459f38088df2af79b53b1acf71d36)

Change-Id: I1334c8b0ab1e1d6cc386cc770c73ddc50af25c2e
libstagefirght: Fix for data loss in A2DP playback with repeat mode

- Data loss is observed in A2DP at the starting of
  second playback with current song repeat mode
-When the file EOS reaches Awesomeplayer calls seek to zero and
 pause the LPAplayer till A2DP thread sent all the data to A2DP.
 Since decoderThread not aware that LPAPlayer in pause state it
 keeps on calling fill buffer.But A2DPThread will be blocked till
 LPAplayer resumes from pause.So buffers which fillbuffer returned
 in pause state are not sent to A2DP and these buffer will be
 over written.
-Added the condition to avoid fillbuffer in decoderThread when
 the LPAplayer is in pause state.

CRs-fixed: 351079
(cherry picked from commit b2ecd5f5b39e3fbee3f73f533897b0d14624244a)

Change-Id: Ib424a5f5794f91df4cad4fbbd7ab27faffcc4ba2
libstagefirght: Fix for music skip in LPA A2DP case

-Portion of music repeating twice after disconnecting and
 connecting A2DP
-When A2DP disconnects, timeplayed will be updated with the data
 sent to A2DP. But Decoder thread already has some decoded data
 which is not sent to A2DP.Here if A2DP connects back decoder
 thread calls fillbuffer with the  time played position.
 Because of this fillbuffer getting some of the decoded data
 which is already decoded earlier.
-To address this issue when the A2DP disconnect and connect happens
 clearing all the buffer which are there in response queue.

CRs-Fixed: 356571
(cherry picked from commit b52619bdc157646278fce30ceb84057370f030c1)

Conflicts:

	media/libstagefright/LPAPlayer.cpp

Change-Id: I98578d4470021757625ad1203682da4bb45cd055
frameworks/base: Fix for LPA volume sequence reversal

- LPA volume is sometimes reversed while doing volume Up&DOwn.
- Two different threads are trying to set volume, one by invoking
  setSessionVolume() and other by invoking setStreamVolume().
  But currently only setStreamVolume() is mutex protected. This
  is leading to race condition and volume set second is getting
  applied first.
- Fix is to acquire mutex in setSessionVolume() before setting
  volume.

CRs-Fixed: 360973
Change-Id: I02ac979bf83c4f3589deb5c83ae816179735aa2b
HDMI: changes to notify audio on hdmi connect.

- When DVI monitor is connected, audio service should not be notified
- remove the redundant changes to check HDCP during boot up
- On connect, check for HDCP/DVI mode and handle audio accordingly

Change-Id: I2af352570eddd4820a9d5ee232f4e2f351c0c524
CRs-fixed: 324931

Update HDMI Notification mechanism and minor cleanup

-- Update HDMI notification mechanism to be based on switch
node, /devices/virtual/switch/hdmi
-- Remove unused SurfaceComposerClient object.
-- Use path /sys/devices/virtual/graphics instead of symlink
/sys/class/graphics
-- Remove support for intents HDMI_CABLE_CONNECTED,
HDMI_CABLE_DISCONNECTED, HDMI_CONNECTED, HDMI_DISCONNECTED.
-- Add support in AudioPolicyManager to handle non HDMI modes.

CRs-fixed: 325697
(cherry picked from commit dd1ef209a42794415b1a06ff947028b26f028fa9)

Change-Id: I07dc58c700b8a2f4c7e086c688e277ce66b3e4c3

HDMIService: Minor fixes in the HDMI Service

- When the cable is connected, set the best mode for HDMI,
  no need to store the current best mode, as this can cause
  issues when a different TV is connected.
- start the HDMIDaemon from the Service, this will help ensure
  HDMI Mirroring works after framework reboot

CRs-fixed: 333941 333497
(cherry picked from commit eb4ade6e6908c49a2e624a71ff1265e14c0b4ec7)

Conflicts:

	services/java/com/android/server/HDMIService.java

Change-Id: Ic87d1703065a284878e7e9c8adac3afb6def56ec

HDMIService: getModeOrder to return order based on resolution

- getModeOrder function used to return order based on the resolution,
  modified that to be based on the best resolution
  This fixes the problem where the HDMI TV used to support 1080p@30Hz
  but still it was picking 1080p@24Hz
- mCurrentMode stores the current display mode on HDMI, reset it when
  the cable is disconnected

(cherry picked from commit 91cb5160ca2b4aaee7cc8c01f6d7162e9c55d67a)

Change-Id: I3efbe385603560330600eab3adeb0da1f1e102aa
Merge "HDMI: changes to notify audio on hdmi connect." into ics