frameworks/base: Add support for wired headset detection

Change-Id: Ia6f26af85aded9decbce93fc2f381f39ff9ab81b
EventHub: Modify the keyboard layout file name for headset button

The keyboard layout file name was formed based on the name of
tabla sound card on current machine. If it doesn't find such
file, it is going to use Generic keyboard layout where the
key mappings are different, even though the scan code is same.
The sound card name differs across different machine types.
So, generalising the keyboard layout file name will work across
all machine types.

CRs-fixed: 344297
Change-Id: I416b6179f51ac98fe7dfae5268ffb58c243540a4
frameworks/base: Fix for headset switch detect

- Headset Switch detect is not functional
- Headset driver on modem in 8x25 and 7x27A targets
  introduces a delay of 500ms before reporting headset
  events to application processor to avoid the problem
  of spurious interrupts being reported due to hardware
  limitation on these targets. Frameworks code in JB
  treats button release event received after 500ms after
  button press as long press event and generates WEBSEARCH
  event. Due to this all the events in 8x25 and 7x27A
  are interpreted as long press events.
- To avoid this problem increase the timeout to more than
  500ms by introducing headset hook delay property for
  these targets.

CRs-fixed: 387247
(cherry picked from commit 5878d849442af33378805f7b9964102119c2fc93)

Change-Id: I03a77666bb217168f7c362bd775dadfbe09fe638
PhoneWindowManager: Release wakelock after headset detection.

- Device does not go to suspend mode after boots up with headset connected.
- Wakelock is not released properly if headsed is detected during boot up.
- Release wakelock in headset intent handler.

CRs-fixed: 384362

(cherry picked from commit 67ddd3c31c7a58aed89f12f956a4d29d58654ed7)

Change-Id: I09f81f4f0e4b2035b13acbb23f6c1dd7b84652c1
frameworks/base: Fix for UI freeze issue with headset insert/removal

- UI freeze is observed while quick insertion and removal of headset
  for multiple times.
- notifyJackSwitchChanged() acquires mHeadsetLock and waits on
  phoneWindowManager lock to call update() as it is a synchronized
  function. sendIntents() is also "synchronized". This function also
  tries to acquire mHeadsetLock. So there is a dead lock, when the
  notifyJackSwitchChanged() acquires the mHeadsetLock before this
  function does.
- update() is called only from notifyJackSwitched() and need not be a
  synchronized function. Removed synchronization on the update() to
  fix the issue.

CRs-Fixed: 390784
(cherry picked from commit 04e683e79c3633e061c71b2ecff4f4c83624d1e0)

Change-Id: I6d274391b68c0a306128d7009bbb651a9b0554f4
Framework: Audio service - add missing pieces from CM9 port

Author: Phil Tunstall
Fix ring/notification volume not restoring correctly on headset (dis)connect

We weren't checking the alias of each stream when restoring, which meant that
for the notification stream volume:
1. The wrong volume level would be stored.
2. The volume level to restore would be retrieved from the wrong place, and then
overwrite the correctly restored ring stream volume.

As well as fixing that I have improved the readability of the code a bit.

 + Change-Id: I95234c2b7ad7dfd4dbd455a56c8a69975c514b50

Author:  Phil Tunstall
Sound preference: Safe volume restore when plugging in a headset (1/2)
When enabled, volumes that were above a threshold (~55%) the previous time
something was connected to the audio jack will be restored to that threshold
rather than their full level.

Affects all sound streams apart from voice call audio.

 + Change-Id: I0007a09ce75b55c95986e38a4cbb24fe4e8200a9

Author: dalingrin
Add separate headset and speaker volumes
This is a simple implementation of keeping separate volume
settings for the wired headset and the speaker without
overhauling the audio system.

This allows a person with sensitive headphones to keep music, ringer
and other stream volumes lower than they would usually keep the
speaker volumes.

 + Change-Id: Ia614c1e3ac548ff4e0104a090cda13b9daef09cb

Author: gsarrica
Allow unlinking of notification sound and ringtone volume.
Thanks to http://forum.aokp.co/ for this.

 + Change-Id: I55db003cc1691fbca5d3e8ea79e088d0622d38ee

Settings side has been merged

Change-Id: I19deecf2346bcf0691dc3a1480791df7b00afb06
AudioManager: Mute on KEYCODE_VOLUME_MUTE

Calls to AudioManager added in KeyguardViewBase and PhoneWindowManager
as well. Toggles mute state by changing the ringer mode.

Change-Id: I7178d3eb7bc62cfc872eb12b3e8d39e4c0a5bf35
frameworks/base: Remove CM headset/speaker volume restore code

- Jelly Bean already has this built in for the media volume stream, but it's
broken by having our own code in there as well.
Other audio streams will no longer have their volume levels restored, and only
media volume will be subjected to the 'safe headset volume restore' cap.

- Cleaned up the 'link notification with ringtone volume' code.

Change-Id: I06e1d159a66e2d6c09c6128c4c946d9578ea90cd
Audio: Restore volume for all streams on headset connect/disconnect

Audio streams which play sound from both speaker and a connected device would
report to AudioService only the speaker as the playback device, meaning volumes
would not be saved for a separate device state. This patch makes it so the
connected device will be reported instead, fixing volume restore on device
change for those streams (alarm, ring, notifications).

Readded safe headset restore capping for all streams.

Patch Set 3: Changed cap to 10/15

Change-Id: Id2e690f7894475ba0086f62342b8eeb163d24da1
Restore correct volumes when headset is plugged

The correct volume levels for <device>_speaker and
<device>_headset are not restored when a headset device
is plugged in or out
Audioservice: fix A2dp support on Samsung's Audio Policy HAL.

Samsung's audio policy HAL doesn't handle A2DP delay commands
correctly which was merged in JB.
Adds a nodelaya2dp config option.

Change-Id: Ib2a1648876ad7b5b21194bd2ad27f5767e46dbb2
fwbs: Add settings from previous picks.

 * We're not necessarily using these yet.

Change-Id: Ib4cecac0ddedd0bc9c104f85e8f5618ffcb57fb7